X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Reply to this topicStart new topic
> Vba To Save As Pdf - Office 2016, Any Version    
post Nov 7 2019, 06:19 PM

Posts: 174
Joined: 28-August 10

I have written some vba within a workbook that unhides specific sheets and saves them as a single pdf. Everything works great, but I need to be able to Save as, and choose where to store the file and what to name it vs, having it go to a default folder and not be able to be named differently each time.
I found some code that should allow this using the Application.GetSaveAsFilename method, but I am so new at all of this, I am not sure how to integrate it into my existing code.
This post has been edited by ginmarie: Nov 7 2019, 06:20 PM
Attached File(s)
Attached File  My_TimeSheet.zip ( 152.2K )Number of downloads: 5
Go to the top of the page
post Nov 9 2019, 11:15 PM

Posts: 20,461
Joined: 10-January 04

here is the syntax

this is the code I modified or added:
   Dim strFilter As String   '---------------------- added
   Dim strTitle As String    '---------------------- added

   'Set path
   strFilepath = "c:\temp\" 'start directory -- change as desired
   'Create the starting path and Filename using indicated cells
   With wksSheet1
      strFileName = .Range("A3").Value & " " & .Range("B3").Value & ".pdf"
      strFileName = strFilepath & strFileName '---------------------- modified
   End With
   'prompt user so the folder or name can be changed
   strFilter = "PDF Files, *.pdf"
   strTitle = "Target Folder and File for Mandate"
   strPathFile = Application.GetSaveAsFilename(strPathFile, strFilter, , strTitle)    

    ' Make the sheets visible
    ThisWorkbook.Sheets("TimePrint").Visible = xlSheetVisible '---------------------- added
    ThisWorkbook.Sheets("ExpPrint").Visible = xlSheetVisible '---------------------- added
    ThisWorkbook.Sheets("MilesPrint").Visible = xlSheetVisible '---------------------- added

Before you can hide sheets again, if there is any issue, you may need to sleep a little bit so the report can finish processing.

have an awesome day,
Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    14th November 2019 - 07:54 PM