jondavis1987
Active Member
- Joined
- Dec 31, 2015
- Messages
- 443
- Office Version
- 2019
- Platform
- Windows
Below is the end of a macro, unless it hits an error but the end of the error handler looks like this as well. This code saves two worksheets as a PDF. The problem is sometimes the users don't remember to only have it on Worksheet "A" after using this. To clarify, this worksheet is a template for reports. So they fill out the information, use the macro to copy the information into the correct workbooks, then can either hit a button deleting all of user entered information essentially resetting the worksheet or they can just type over the user entered information. If they don't make sure only Worksheet A is selected when they start typing and run the macro again some weird stuff happens. I've read you should avoid using the select method whenever possible. So what would be the appropriate way to only select sheet A at the end of this?
VBA Code:
' Export source workbook to PDF
With srcWB
fName = srcWB.Sheets("A").Range("A!F19").Value
Sheets(Array("A", "Sheet2")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\" & Environ("username") & "\Dropbox\Quality Control\Asphalt\Asphalt Reports\" & fName, _
openafterpublish:=True, ignoreprintareas:=False
End With
Exit Sub