Export in code not working

jrisebo

Active Member
Joined
Mar 15, 2011
Messages
312
Office Version
  1. 365
Platform
  1. Windows
I have this code below. When it exports, it only picks a PDF size of 16.04x2075. How Do I get it just to be letter size?

VBA Code:
Private Sub CommandButton1_Click()


For x = 2 To 100 'increase the 100 to a larger number if you ever have more than 100 sheets

If Sheets("Sheet1").Range("A" & x).Value = "" Then Exit Sub

Sheets("Table1").Range("A1").Value = Sheets("Sheet1").Range("A" & x).Value

Sheets("Table1").Range("A19").Value = Sheets("Sheet1").Range("A" & x).Value

Sheets("Table1").Range("E1").Value = Sheets("Sheet1").Range("C" & x).Value

Sheets("Table1").Range("E19").Value = Sheets("Sheet1").Range("C" & x).Value

Sheets("Table1").Range("H24").Value = Sheets("Sheet1").Range("C" & x).Value

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.path & "\S&R" & x & ".pdf"

Next
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Before running the macro you must set the sheet printing settings, I assume it is the sheet "Table1". Then select the sheet Table1.
Use the Page Setup dialog box to set up layout and print options of a page.
Click on the Page Layout tab, then in the Page Setup group, click the Dialog Box Launcher .
Set Letter in Papper size option:

1714701841659.png


Try your macro.
 
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,637
Members
449,461
Latest member
kokoanutt

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