|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Saving embedded image to disc
I am using VBA (Excel) to automate a process.
In Excel in have the following code: ActiveSheet.OLEObjects.Add(Filename="C:\sample.mid", link = false, DisplayAsIncon = false).select This works as expected. However what I need to be able to do is, using a seperate VBscript, save this file to disc. It's probably very obvious but I can't see how to do it. Can somebody tell me how ? (and can I use the same technique for jpg files?) Thank you Last edited by Eagle Eye : September 12th, 2003 at 03:57 AM. |
|
#2
|
|||
|
|||
|
You would try export method or saveas method.
http://www.4guysfromrolla.com/webtech/022801-1.shtml Private Sub createPage() 'Declarations Dim ExcelAp As New Excel.Application() Dim ExcelWb As Excel.Workbook Dim ExcelWs As Excel.Worksheet ExcelAp.Application.SheetsInNewWorkbook = 1 ExcelWb = ExcelAp.Workbooks.Add ExcelWs = ExcelWb.ActiveSheet 'Show the created excel worksheet ExcelWs.Application.Visible = True 'Add data to the sheet ExcelWs.Name = "Report" ExcelWs.Cells(1, 1).Value = "Machine Number" 'In cell A1 the text 'Test1' will be placed. ExcelWs.Cells(1, 2).Value = "Client" ExcelWs.Cells(1, 3).Value = "City" ExcelWs.Cells(1, 4).Value = "State" ExcelWs.Cells(1, 5).Value = "Contact" ExcelWs.Cells(1, 6).Value = "Contact#" ExcelWs.Cells(1, 7).Value = "Contact Email" ExcelWs.Cells(1, 8).Value = "Citrix Y/N" ExcelWs.Cells(1, 9).Value = "Comments/Updated Info" ' Save the sheet to C:\Test.xls directory. ExcelWs.SaveAs("Test.xls") 'Close Workbooks ExcelWb.Close() ExcelAp.Quit() 'Close all objects ExcelWs = Nothing ExcelWb = Nothing ExcelAp = Nothing End Sub |
|
#3
|
|||
|
|||
|
Thanks for that but I obviously didn't make myself clear.
What I actually what to be able to do is to save the embedded object to a file not the whole spresadsheet. |
|
#4
|
|||
|
|||
|
I am trying to do a similar thing -
I have taken over a site design project for a customer using ASP and MS-SQL.. They would like an inventory page based on a huge excel file. To start with, they gave me a small one with 200 rows, but they have a bigger 2000 row sheet. Column 1 is a description, column 2 is a unique product id, and column 3 is some sort of copy and pasted image of the product, and I need to display these on the page. I guess I want to somehow export all the images in the 3rd column into individual jpg files, and name them according to the id. For instance, the image that is sitting in the third column of productid 1234 would be saved as 1234.jpg - then I could export the sheet as a CSV and make a simple database query to display the description, id, and image. I have no idea how to go about exporting these images from Excel in any convenient fashion, and name them according to another column in the row. Any ideas? |
|
#5
|
|||
|
|||
|
VB has a SavePicture statement that will extract a graphic to a file, but I don't know if it's in Excel VBA or not.
|
|
#6
|
|||
|
|||
|
Thanks, Doug -
SavePicture _does_ seem ideal, but it is not in the Methods section of the MSDN MS Excel VB Reference. Nonetheless, I tried it with the first picture by executing this statement: ---> Set myDocument = Worksheets(1) SavePicture myDocument.Shapes(1), "C:/test.bmp" <--- ...as a macro. the error I got was: ---> Run-time error 13 Type mismatch. <--- This seems to suggest that the method is available, but I am passing the wrong thing to it (Shape). Since the method documentation is not where I would think it is in MSDN, I still think this might be worth pursuing, if I only knew what to pass it. Am I flogging a dead horse trying to get this to work with Excel VB, or am I just passing a wrong argument type? |
|
#7
|
|||
|
|||
|
If the savepicture method is not documented in the Excel VBA documentation I wouldn't try to use it in my code. And I don't see anything about this statement in Excel 2000 VB reference. I searched the Excel online help for savepicture and nothing showed up.
|
|
#8
|
|||
|
|||
|
Thanks Doug. I guess I was hoping for a miracle. I am using Excel 2002, and came to the same conclusion.
To cut my losses, I will just go forward doing each one manually. If anyone has a good idea, I'd love to hear it before the 2000 some-odd row spreadsheet comes my way! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Saving embedded image to disc |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|