Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-14-2014, 07:42 AM
ChrisBrewster ChrisBrewster is offline Saving graphics using captions Windows 7 64bit Saving graphics using captions Office 2010 64bit
Advanced Beginner
Saving graphics using captions
 
Join Date: Jan 2014
Posts: 36
ChrisBrewster is on a distinguished road
Default 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
Attached Files
File Type: txt VBA macro - Extract Word graphics.txt (3.7 KB, 12 views)
Reply With Quote
  #2  
Old 11-15-2014, 01:08 AM
gmayor's Avatar
gmayor gmayor is offline Saving graphics using captions Windows 7 64bit Saving graphics using captions Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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)
The function would be
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
Greg is a good friend who I work with a lot so I have used his vba formatting style, to match the other processes.

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
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving graphics using captions VBA to insert captions without appending to existing captions Marrick13 Word VBA 17 03-21-2023 07:51 PM
Saving graphics using captions 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

Other Forums: Access Forums

All times are GMT -7. The time now is 10:28 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft