#1
|
|||
|
|||
Saving graphics using captions
I need to save the graphics in Word files, using an altered version of each figure's caption for the file name. VBA doesn't have a function like the "Save Picture As" function (on the menu when you right-click a graphic), which is how I thought I would create a macro. I hunted around and found a very good script, which is attached. It puts the figure captions in an array, saves the Word file as HTML in a new folder, deletes non-graphic files from that folder, and assigns the captions as file names for the graphic files.
This script does everything I need, except that it works only on PNG files. JPG files are saved, but with numbered file names. (The critical step for naming the file specifies the ".png" extension.) My VBA knowledge isn't good enough to modify this script. Can anyone suggest how to change it so that it detects the file type, and makes the correct caption for either JPG or PNG? The script is in the attached file, and I found it at this link: http://www.mrexcel.com/forum/general...le-folder.html |
#2
|
||||
|
||||
Greg should be sleeping at the moment, but looking at his code I suspect the following should work, though I haven't tested it.
You will need a function to get the original extension and add that instead of .png e.g. Code:
Name strBasePath & strExtractionFolder & "_files\" & _ strName As strBasePath & strExtractionFolder & "_files\" & _ strImageName & GetExtension(strfname) Code:
Function GetExtension(ByRef StrFilename As String) As String GetExtension = VBA.Right(StrFilename, Len(StrFilename) - InStrRev(StrFilename, Chr(46)) + 1) lbl_Exit: Exit Function Err_NoExtension: GetExtension = vbNullString Resume lbl_Exit End Function You can get rid of the SpecialFolderPath function as your modified version of the code doesn't call it. In any case it is not a good idea to save to the Desktop. That is a special type of folder and some write functions from VBA may not work as expected when it is used.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA to insert captions without appending to existing captions | Marrick13 | Word VBA | 17 | 03-21-2023 07:51 PM |
Captions, self defined | stresscalcs | Word | 9 | 01-29-2015 04:47 PM |
Optional Captions | RobertWA | PowerPoint | 0 | 02-21-2014 09:30 AM |
Captions/Styles | NWoffice | Word | 5 | 10-06-2011 10:26 AM |
Captions | dwilliams | Word | 0 | 10-07-2009 08:30 AM |