Problem With Macros

TooZippy

Board Regular
Joined
Dec 30, 2018
Messages
70
I have two spreadsheets in one file that are identical. In one spreadsheet I highlighted an area and named it "abc". I created a macro in this spreadsheet to print area "abc" to my printer and called it "printabc". In my second spreadsheet in the same file I highlighted a similar area and named it "def". I created a macro in that spreadsheet to print area "def" to a .pdf file on my computer and called it "savedef".

When I click on the "Form Control" icon on either spreadsheet to run each macro it prints both spreadsheets to the printer. It seems that the "savedef" macro is overrun. I made sure that I Assigned the right macro to the right spreadsheet. When I edit either of the macros they both look identical. Any suggestions to get one of them to print to the printer and the other to print a .pdf file to my computer?

Thank you,
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
.
Code:
Option Explicit


Sub SveRngPDF()
Sheets("Sheet1").Range("A1:K16").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "C:\Users\My\Desktop\Sheet1.pdf", Quality:= _
    xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=True
End Sub

The above code saves the Range ("A1:K16") of Sheet 1 as a PDF file, to the desktop and names it Sheet1.pdf.

You will need to edit the sheet name (if different) and the path where to save and name the file.
 
Upvote 0
Logit, Thank you for the Code. I copied and pasted it into my file, but I get the error message "Compile error: Ambiguous name detected: SveRngPDF". I tried to run it after I changed the range, file name, path and sheet name and I got the error message. Any suggestions???

Thank you
 
Upvote 0
That message normally means you have 2 macro's with the same name.
 
Upvote 0
You can't have more than one macro with the same name....remove or rename one of them.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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