Trying to get my excel macro to work in Word

graduate106

Board Regular
Joined
Jul 14, 2011
Messages
91
Hi i have a good macro designated to a keyboard shortcut which saves my excel worksheet as a PDF to a particular folder on my hard drive (see below).

I know this is not strictly a "Word" forum, but womndered if anyone else could point me in the direction of tweaking this so that it worked in Word. I have done a few google searches but i'm struggling to get anything to work. I have never written a macro in Word before.

Any help appreciated, thanks

Sub SAVE_AS_PDF()
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"V:\" & (ActiveSheet.Name) & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
MsgBox ("PDF successfully saved to V: drive!")
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Dont worry - nailed it!

For those interested:

Sub SAVE_AS_PDF()

ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"V:\" & ActiveDocument.Name & ".pdf", ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False


MsgBox ("PDF successfully saved to V:drive!")
End Sub
 
Upvote 0
Rather simpler is:
Code:
Sub SAVE_AS_PDF()
With ActiveDocument
  .SaveAs2 FileName:="V:\" & Left(.Name, InStrRev(.Name, ".")) & "pdf", Format:=wdFormatPDF
End With
MsgBox ("PDF successfully saved to V:drive!")
End Sub
Note: Your Excel and Word subs both leave the .xlsx & .docx extensions in the PDF filenames - mine doesn't.
 
Upvote 0

Forum statistics

Threads
1,225,684
Messages
6,186,426
Members
453,354
Latest member
Ubermensch22

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top