Using XLM macro’s

David Looney

Board Regular
Joined
Aug 12, 2006
Messages
60
I’m using ExecuteExcel4Macro PAGE.SETUP and I’m trying to use the SCALE argument to set the page to fit 1 page wide by any length long. Help says to pass an array which I can’t figure out how to do.

Help says set SCALE to TRUE to fit 1 page by 1 page which works fine. Using a number i.e. 50 sets scale to 50% which works fine. How do I pass an array in XLM? Below is what help says.:

HELP FILE
For worksheets and macros, you can specify the number of pages that the printout should be scaled to fit. Set scale to a two-item horizontal array, with the first item equal to the width and the second item equal to the height. If no constraint is necessary in one direction, you can set the corresponding value to #N/A.

Scale can also be a logical value. To fit the print area on a single page, set scale to TRUE.
 
Argument13 is what you would set in the dialog method.
Code:
'head, foot, left, right, top, bot, hdng, grid, h_cntr, v_cntr, orient, paper_size, scale,
'pg_num , pg_order, bw_cells, quality, head_margin, foot_margin, Notes, Draft
Sub Test1()
  Application.SendKeys "{ENTER}", False
  Application.Dialogs(xlDialogPageSetup).Show _
        Arg1:="&""Arial,Bold""&18SampleTable�@", _
        Arg3:=0.590551181102362, _
        Arg4:=0.590551181102362, _
        Arg5:=0.866141732283465, _
        Arg6:=0.275590551181102, _
        Arg9:=True, _
        arg10:=True, _
        Arg11:=2, _
        Arg12:=8, _
        Arg13:=Array(50, 10), _
        Arg18:=0.590551181102362, _
        Arg19:=0.511811023622047
End Sub
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
This looks bad, replying to myself...

Anywho, use {}'s to define an array for the parameter 13, scale.
Code:
Sub Macro1_Version4()
    Dim St As String
    St = "PAGE.SETUP(, , " & _
                     "1.5, 1.5, 1.5, 1.5" & _
                     ", 0, False, False, False, 1, 1, True, 1, 1,False, , " & _
                     "1, 1" & _
                     ", False)"
'or using scale other than 1 to 1 as the True above.
    St = "PAGE.SETUP(, , " & _
                 "1.5, 1.5, 1.5, 1.5" & _
                 ", 0, False, False, False, 1, 1, " & _
                 "{5,1}, 1, 1,False, , " & _
                 "1, 1" & _
                 ", False)"
    Application.ExecuteExcel4Macro St
End Sub
 
Upvote 0
Are you crazy? Please reply to yourself as often as needed, you just SOLVED the problem, many, many thanks. I had just decided that passing an array must be done differently in the old xlm days so I did a search and found this note:

Arrays s/b passed as a string like ‘{1,2,3}’

I was just beginning to play with that when I seen you had posted the answer!

Thanks!
 
Upvote 0
Since we are just passing a string, one can do this if one wants to dim the array and set the values first.

Code:
Sub Macro1_Version4()
    Dim St As String, a As Variant
    a = Array(5, 3)
    St = "PAGE.SETUP(, , " & _
                     "1.5, 1.5, 1.5, 1.5" & _
                     ", 0, False, False, False, 1, 1, " & _
                     "{" & Join(a, ",") & "}" & ",1, 1,False, , " & _
                     "1, 1" & _
                     ", False)"
    Application.ExecuteExcel4Macro St
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,558
Members
452,928
Latest member
101blockchains

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