Button click macro question

steve400243

Active Member
Joined
Sep 15, 2016
Messages
429
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello, I am trying to get this code to Save to the following location - X:\SEA Shares\Surface Trans\QUOTES

Can someone help me with amending the code to save to correct location?

Code:
Sub Button1_Click()
'
' Button1_Click Macro
'


'
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("D5").Value _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
You have one of two choices:

1. Change whatever value you have in cell D5 to include the path way (ex: instead of having D5 be "filename" you have it be "X:\SEA Shares\Surface Trans\QUOTES\filename")
2. In the filename section, change it to:

Filename:="
X:\SEA Shares\Surface Trans\QUOTES" & Range("D5").value

Note - you might want to consider some error handling for people inputting junky file names into D5
 
Upvote 0
Thanks gmhumphr, Appreciate your help. D5 is a quote number that is generated by another code based on date and time. No user inputting. I want it to save as this number.

Code:
Private Sub Workbook_Open()
With Sheets("Sheet1").Range("D5")
    .Value = Format(Date + Time, "yyyymmddhhmm")
End With
End Sub
 
Upvote 0
Here is where I am at now, I cannot get it to work?

Code:
Sub Button1_Click()
'
' Button1_Click Macro
'


'
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=("X:\SEA Shares\Surface Trans\QUOTES") & Range("D5").Value _
     , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
 
Upvote 0
No need for parenthesis, and I neglected to include the final slash: Filename:="X:\SEA Shares\Surface Trans\QUOTES" & Range("D5").Value
 
Last edited:
Upvote 0
I'm sure its my limited knowledge of Macros, but i cannot get this to save as the value that is generated in D5. Here was another try -

Code:
Sub Button1_Click()
'
' Button1_Click Macro
'




'
ChDir "X:\SEA Shares\Surface Trans\QUOTES"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("D5").Value _
     , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,509
Messages
6,125,215
Members
449,215
Latest member
texmansru47

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