Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-23-2014, 11:41 AM
mbesspiata mbesspiata is offline Open and save Word files Windows 7 64bit Open and save Word files Office 2010 64bit
Advanced Beginner
Open and save Word files
 
Join Date: Mar 2011
Location: Virginia
Posts: 57
mbesspiata is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 05-23-2014, 11:54 AM
Charles Kenyon Charles Kenyon is offline Open and save Word files Windows 7 64bit Open and save Word files Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 7,429
Charles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud of
Default

Recorded macros are seldom good code. This one is no exception.

You could use:
Code:
      Application.Dialogs(wdDialogFileOpen).Show
in place of your code opening the file. That simply lets you pick the file.
Reply With Quote
  #3  
Old 05-23-2014, 12:06 PM
mbesspiata mbesspiata is offline Open and save Word files Windows 7 64bit Open and save Word files Office 2010 64bit
Advanced Beginner
Open and save Word files
 
Join Date: Mar 2011
Location: Virginia
Posts: 57
mbesspiata is on a distinguished road
Default

OK. What part of my opening macro would I replace with the part you submitted?

Mike
Reply With Quote
  #4  
Old 05-23-2014, 07:15 PM
Charles Kenyon Charles Kenyon is offline Open and save Word files Windows 7 64bit Open and save Word files Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 7,429
Charles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud ofCharles Kenyon has much to be proud of
Default

You could replace the entire macro or everything except the first line.
This opens the FileOpen dialog.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open and save Word files 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
Open and save Word files Word 2007 won't let me open or save documents! iteach Word 10 11-25-2011 12:23 PM
Open and save Word files VBA to open files in Word Lu_Argentina Word VBA 3 07-26-2011 05:47 PM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 08:40 AM.


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