Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-03-2019, 03:29 PM
bearcublandon bearcublandon is offline Insert variable in path name Windows 10 Insert variable in path name Office 2016
Novice
Insert variable in path name
 
Join Date: Dec 2018
Posts: 24
bearcublandon is on a distinguished road
Default Insert variable in path name

I have the following code that I recorded with the macro recorder.



I would like to save the file in this location but put use the input box to insert the file name. How do I incorporate the input box in the macro. It's been awhile for me doing this so I'm kinda rusty.

Sub Save_To()
'
' Save_To Macro
'
'
Dim Name As String

InputBox "Enter name", "file" = Name

ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"P:\My Documents\Excel\Stock Information\Good Files\PDF\Name.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 _
"P:\My Documents\Excel\Stock Information\Good Files\PDF\"
End Sub

I inserted Name in the path way but I get an error message at this point. The name of the file is showing up as Name but I would like to enter the name in the input box and transfer this into the directory.

Thank you for your help,

Michael
Reply With Quote
  #2  
Old 01-03-2019, 05:20 PM
macropod's Avatar
macropod macropod is offline Insert variable in path name Windows 7 64bit Insert variable in path name Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,382
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Is there a reason for not using SaveAs, or the FileSave dialogue? That said, you could use:
Code:
Dim StrNm As String
StrNm = InputBox("PDF File Name")
StrNm = "P:\My Documents\Excel\Stock Information\Good Files\PDF\" & StrNm & ".pdf"
ActiveDocument.ExportAsFixedFormat OutputFileName:=StrNm, _
  ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, _
  OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
  Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
  CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
  BitmapMissingFonts:=True, UseISO19005_1:=False
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-03-2019, 06:08 PM
bearcublandon bearcublandon is offline Insert variable in path name Windows 10 Insert variable in path name Office 2016
Novice
Insert variable in path name
 
Join Date: Dec 2018
Posts: 24
bearcublandon is on a distinguished road
Default

this isi great thank you. I just used the macro recorder but I didn't look at the code (I'm kinda on a deadline).

Thank you for cleaning it up and making it better.

Michael
Reply With Quote
  #4  
Old 01-03-2019, 07:32 PM
macropod's Avatar
macropod macropod is offline Insert variable in path name Windows 7 64bit Insert variable in path name Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,382
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Of course, you could use:
Code:
With Application.Dialogs(wdDialogFileSaveAs)
  .Format = wdFormatPDF
  .Show
End With
instead of the code in post #2.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 01-03-2019, 07:40 PM
bearcublandon bearcublandon is offline Insert variable in path name Windows 10 Insert variable in path name Office 2016
Novice
Insert variable in path name
 
Join Date: Dec 2018
Posts: 24
bearcublandon is on a distinguished road
Default

I like that , what does this statement do - with the showing of the dialog?

By the way, every time I save a file Microsoft Ege keeps popping up trying to display the PDF document (which never happens, the new tab always remains blank).

I can see the PDF in google or adobe but not Microsoft Edge.

I really don't want to see the PDF's after they're saved. Is there a way of preventing Microsoft Edge from being activated every time I save a word document to a PDF (it doesn't do anything for me)?

Thank you for your help.

Michael
Reply With Quote
  #6  
Old 01-03-2019, 08:14 PM
macropod's Avatar
macropod macropod is offline Insert variable in path name Windows 7 64bit Insert variable in path name Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,382
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by bearcublandon View Post
I like that , what does this statement do - with the showing of the dialog?
Well, with the dialogue open, you can insert the filename of your choice, then click OK to save.
Quote:
Originally Posted by bearcublandon View Post
By the way, every time I save a file Microsoft Ege keeps popping up trying to display the PDF document (which never happens, the new tab always remains blank).
That's because your code (which I replicated) has:
OpenAfterExport:=True
If you set that to False, Edge won't keep popping up trying to display it. Evidently there's some communication problem with Edge if all you're getting is a blank page.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 01-03-2019, 08:17 PM
bearcublandon bearcublandon is offline Insert variable in path name Windows 10 Insert variable in path name Office 2016
Novice
Insert variable in path name
 
Join Date: Dec 2018
Posts: 24
bearcublandon is on a distinguished road
Default

Ah, that is good to know. I'll change the code tomorrow from True to False.

Michael
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert variable in path name VBA to Insert variable rows based on a data in active cell Marcia Excel Programming 4 07-28-2018 10:02 AM
Insert variable in path name Insert a Variable Row to SUM SubTotal ChrisOK Excel Programming 3 02-12-2018 10:46 AM
I want to create a bar chart of multiple variable. Then I need to draw trend lin of those variable shimulsiddiquee Excel 1 05-16-2017 07:39 AM
Run Time Error '91': Object variable or With block variable not set using Catalogue Mailmerge Berryblue Mail Merge 1 11-13-2014 05:36 PM
Insert variable in path name insert auto path & file name in ppt 2013 rideninc PowerPoint 1 01-28-2014 05:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:06 PM.


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