+ Reply to Thread
Results 1 to 3 of 3

Can someone help me with this Macro

  1. #1
    Forum Contributor
    Join Date
    12-31-2004
    Posts
    160

    Can someone help me with this Macro

    What is wrong with this recorded macro?
    I am trying to widen out the margins on the print preview screen with a macro,
    but it errors out. The error is highlighted red stepping through the code produces an error on each line same place.
    If I knew how I would write a sub in VBA to do this but I don't know how to make the excel user interface do what I need I can only make the cells do what I need in VBA.
    Any help would be apperciated

    Thanks
    Charles

    Note: This is a recorded macro not written by me!

    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 1/5/2005 by Charles E.Alexander
    '
    ' Keyboard Shortcut: Ctrl+x
    '
    With ActiveSheet.PageSetup
    .LeftMargin = Application.InchesToPoints()
    .RightMargin = Application.InchesToPoints()
    .TopMargin = Application.InchesToPoints()
    .BottomMargin = Application.InchesToPoints()
    .HeaderMargin = Application.InchesToPoints(0.15)
    .FooterMargin = Application.InchesToPoints()
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    End With
    With ActiveSheet.PageSetup
    .LeftMargin = Application.InchesToPoints()
    .RightMargin = Application.InchesToPoints()
    .TopMargin = Application.InchesToPoints(0.33)
    .BottomMargin = Application.InchesToPoints()
    .HeaderMargin = Application.InchesToPoints()
    .FooterMargin = Application.InchesToPoints()
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    End With
    With ActiveSheet.PageSetup
    .LeftMargin = Application.InchesToPoints(0.75)
    .RightMargin = Application.InchesToPoints()
    .TopMargin = Application.InchesToPoints()
    .BottomMargin = Application.InchesToPoints()
    .HeaderMargin = Application.InchesToPoints()
    .FooterMargin = Application.InchesToPoints()
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    End With
    With ActiveSheet.PageSetup
    .LeftMargin = Application.InchesToPoints(0.25)
    .RightMargin = Application.InchesToPoints()
    .TopMargin = Application.InchesToPoints()
    .BottomMargin = Application.InchesToPoints()
    .HeaderMargin = Application.InchesToPoints()
    .FooterMargin = Application.InchesToPoints()
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    End With
    With ActiveSheet.PageSetup
    .LeftMargin = Application.InchesToPoints()
    .RightMargin = Application.InchesToPoints(0.25)
    .TopMargin = Application.InchesToPoints()
    .BottomMargin = Application.InchesToPoints()
    .HeaderMargin = Application.InchesToPoints()
    .FooterMargin = Application.InchesToPoints()
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    End With
    ActiveWindow.SelectedSheets.PrintPreview
    End Sub

  2. #2
    Forum Contributor
    Join Date
    12-31-2004
    Posts
    160

    Ok I figured this out

    I just erased each line that errored out!
    I was wrong I thought each Line Produced the same error.
    Anyway tyhis is what I ended up with which works great except How do I make this macro work everytime I open a new file in excel?
    The macro is in the workbook I had open when I made it!


    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 1/5/2005 by Charles E.Alexander
    '
    ' Keyboard Shortcut: Ctrl+x
    '
    With ActiveSheet.PageSetup
    .HeaderMargin = Application.InchesToPoints(0.15)
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    End With
    With ActiveSheet.PageSetup
    .TopMargin = Application.InchesToPoints(0.33)
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    End With
    With ActiveSheet.PageSetup
    .LeftMargin = Application.InchesToPoints(0.75)
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    End With
    With ActiveSheet.PageSetup
    .LeftMargin = Application.InchesToPoints(0.25)
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    End With
    With ActiveSheet.PageSetup
    .RightMargin = Application.InchesToPoints(0.25)
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    End With

    End Sub

  3. #3
    Forum Contributor
    Join Date
    12-31-2004
    Posts
    160

    Cool How to make macro available in a new workbook

    I finally got a macro working for what I need only problem,
    When I open my workbook and it is a new workboo each day the macro was in the original workbook.
    Is there a way to make the macro available in a new workbook?

    Thanks
    Charles

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1