#1
|
|||
|
|||
Open and save Word files
I have a macro to format a text file and I want to save it as a pdf file when formatted. I want a macro to do the opening of the text file and the saving as a pdf file. I recorded these operations but I need to know how to input code so that the file name is not specific. I want it to ask me what file to open and what the file name should be when formatting to pdf. Here is what I recorded.
Macro1 Macro ' ' ActiveDocument.ExportAsFixedFormat OutputFileName:= _ "C:\Users\mbesspiata\Desktop\Dayton Countsheet File.pdf", ExportFormat:= _ wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _ wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _ Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _ CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _ BitmapMissingFonts:=True, UseISO19005_1:=False ChangeFileOpenDirectory "C:\Users\mbesspiata\Desktop\" Windows("Document1").Activate ActiveWindow.Close End Sub Sub Macro2() ' ' Macro2 Macro ' ' ChangeFileOpenDirectory "C:\Users\mbesspiata\Desktop\" Documents.Open FileName:="Dayton Countsheet File.txt", ConfirmConversions _ :=False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _ PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _ WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:="", _ Encoding:=1252 End Sub Mike |
#2
|
|||
|
|||
Recorded macros are seldom good code. This one is no exception.
You could use: Code:
Application.Dialogs(wdDialogFileOpen).Show |
#3
|
|||
|
|||
OK. What part of my opening macro would I replace with the part you submitted?
Mike |
#4
|
|||
|
|||
You could replace the entire macro or everything except the first line.
This opens the FileOpen dialog. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA to open files in Word | Lu_Argentina | Word VBA | 5 | 02-22-2022 02:41 PM |
Save Word Files as OLE Bound Objects | KSReynolds | Word VBA | 1 | 12-18-2013 05:51 PM |
Can't save Large Word files to html | Gardener | Word | 0 | 12-25-2011 09:37 AM |
Word wont save when Outlook is open. | erik2282 | Office | 0 | 11-26-2011 08:00 AM |
Word 2007 won't let me open or save documents! | iteach | Word | 10 | 11-25-2011 12:23 PM |