+ Reply to Thread
Results 1 to 6 of 6

Can't get simple macro to run

  1. #1
    Abi
    Guest

    Can't get simple macro to run

    Okay. Pretend I'm a totally idiot and and can't seem to get anything to work
    right!

    Now, I have done a few macros before (basically just recording them and then
    assigning them to controls - but have not done this in Excel before, so maybe
    I'm missing something here). I don't know how to code at all.

    ALL I want to do is have a user click on one button and - viola - the macro
    does its thing.

    The macro I have recorded prints several sheets in a workbook. It works. I
    tried it out and it works.

    Here's what I've done so far.
    1 - recorded a macro to print pages.
    2 - created a button on one sheet. Right-clicked on it and selected View
    Code.
    3 - I inserted my macro in the VB editor by opening up the macro and
    copy/pasting it into the VB editor after:
    Private Sub CommandButton1_Click ( )
    End Sub
    -------------------------------------------------------------
    Sub PrintQuote()
    '
    ' PrintQuote Macro
    ' Macro recorded 1/12/2005 by XXX
    '

    '
    Sheets("Title Page").Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    Sheets(Array("Thankyou", "AV EQ", "QuoteSummary", "Terms", "Punch
    List")).Select
    Sheets("Thankyou").Activate
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    End Sub

    Can someone please tell me where I've screwed up? I thought this would be
    the easy part of this whole project I've been working on!

  2. #2
    Guest

    Can't get simple macro to run

    hi,
    if you put the code in the vb editor as a general module
    then the button has to call the macro
    Right click the button in design mode, click view code.
    if nothing is there, add this: call yourmacroname
    If there is code there, it should be running if it has the
    click event.

    >-----Original Message-----
    >Okay. Pretend I'm a totally idiot and and can't seem to

    get anything to work
    >right!
    >
    >Now, I have done a few macros before (basically just

    recording them and then
    >assigning them to controls - but have not done this in

    Excel before, so maybe
    >I'm missing something here). I don't know how to code at

    all.
    >
    >ALL I want to do is have a user click on one button and -

    viola - the macro
    >does its thing.
    >
    >The macro I have recorded prints several sheets in a

    workbook. It works. I
    >tried it out and it works.
    >
    >Here's what I've done so far.
    >1 - recorded a macro to print pages.
    >2 - created a button on one sheet. Right-clicked on it

    and selected View
    >Code.
    >3 - I inserted my macro in the VB editor by opening up

    the macro and
    >copy/pasting it into the VB editor after:
    >Private Sub CommandButton1_Click ( )
    >End Sub
    >----------------------------------------------------------

    ---
    >Sub PrintQuote()
    >'
    >' PrintQuote Macro
    >' Macro recorded 1/12/2005 by XXX
    >'
    >
    >'
    > Sheets("Title Page").Select
    > ActiveWindow.SelectedSheets.PrintOut Copies:=1,

    Collate:=True
    > Sheets(Array("Thankyou", "AV

    EQ", "QuoteSummary", "Terms", "Punch
    >List")).Select
    > Sheets("Thankyou").Activate
    > ActiveWindow.SelectedSheets.PrintOut Copies:=1,

    Collate:=True
    >End Sub
    >
    >Can someone please tell me where I've screwed up? I

    thought this would be
    >the easy part of this whole project I've been working

    on!
    >.
    >


  3. #3
    Bernie Deitrick
    Guest

    Re: Can't get simple macro to run

    Private Sub CommandButton1_Click ( )

    PrintQuote
    End Sub

    and the code for the PrintQuote need to go into a standard codemodule, not
    the worksheet's codemodule.

    Or, you could simply use

    Private Sub CommandButton1_Click ( )
    Sheets("Title Page").Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    Sheets(Array("Thankyou", "AV EQ", "QuoteSummary", "Terms", "Punch
    List")).Select
    Sheets("Thankyou").Activate
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    End Sub


    HTH,
    Bernie
    MS Excel MVP

    "Abi" <[email protected]> wrote in message
    news:[email protected]...
    > Okay. Pretend I'm a totally idiot and and can't seem to get anything to

    work
    > right!
    >
    > Now, I have done a few macros before (basically just recording them and

    then
    > assigning them to controls - but have not done this in Excel before, so

    maybe
    > I'm missing something here). I don't know how to code at all.
    >
    > ALL I want to do is have a user click on one button and - viola - the

    macro
    > does its thing.
    >
    > The macro I have recorded prints several sheets in a workbook. It works.

    I
    > tried it out and it works.
    >
    > Here's what I've done so far.
    > 1 - recorded a macro to print pages.
    > 2 - created a button on one sheet. Right-clicked on it and selected View
    > Code.
    > 3 - I inserted my macro in the VB editor by opening up the macro and
    > copy/pasting it into the VB editor after:
    > Private Sub CommandButton1_Click ( )
    > End Sub
    > -------------------------------------------------------------
    > Sub PrintQuote()
    > '
    > ' PrintQuote Macro
    > ' Macro recorded 1/12/2005 by XXX
    > '
    >
    > '
    > Sheets("Title Page").Select
    > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    > Sheets(Array("Thankyou", "AV EQ", "QuoteSummary", "Terms", "Punch
    > List")).Select
    > Sheets("Thankyou").Activate
    > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    > End Sub
    >
    > Can someone please tell me where I've screwed up? I thought this would be
    > the easy part of this whole project I've been working on!




  4. #4
    Abi
    Guest

    Re: Can't get simple macro to run

    I used the second suggestion (copied it in) and the button printed the first
    page (Title Page) but then I got a run-time error for the rest. ???

    "Bernie Deitrick" wrote:

    > Private Sub CommandButton1_Click ( )
    >
    > PrintQuote
    > End Sub
    >
    > and the code for the PrintQuote need to go into a standard codemodule, not
    > the worksheet's codemodule.
    >
    > Or, you could simply use
    >
    > Private Sub CommandButton1_Click ( )
    > Sheets("Title Page").Select
    > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    > Sheets(Array("Thankyou", "AV EQ", "QuoteSummary", "Terms", "Punch
    > List")).Select
    > Sheets("Thankyou").Activate
    > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    > End Sub
    >
    >
    > HTH,
    > Bernie
    > MS Excel MVP
    >
    > "Abi" <[email protected]> wrote in message
    > news:[email protected]...
    > > Okay. Pretend I'm a totally idiot and and can't seem to get anything to

    > work
    > > right!
    > >
    > > Now, I have done a few macros before (basically just recording them and

    > then
    > > assigning them to controls - but have not done this in Excel before, so

    > maybe
    > > I'm missing something here). I don't know how to code at all.
    > >
    > > ALL I want to do is have a user click on one button and - viola - the

    > macro
    > > does its thing.
    > >
    > > The macro I have recorded prints several sheets in a workbook. It works.

    > I
    > > tried it out and it works.
    > >
    > > Here's what I've done so far.
    > > 1 - recorded a macro to print pages.
    > > 2 - created a button on one sheet. Right-clicked on it and selected View
    > > Code.
    > > 3 - I inserted my macro in the VB editor by opening up the macro and
    > > copy/pasting it into the VB editor after:
    > > Private Sub CommandButton1_Click ( )
    > > End Sub
    > > -------------------------------------------------------------
    > > Sub PrintQuote()
    > > '
    > > ' PrintQuote Macro
    > > ' Macro recorded 1/12/2005 by XXX
    > > '
    > >
    > > '
    > > Sheets("Title Page").Select
    > > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    > > Sheets(Array("Thankyou", "AV EQ", "QuoteSummary", "Terms", "Punch
    > > List")).Select
    > > Sheets("Thankyou").Activate
    > > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    > > End Sub
    > >
    > > Can someone please tell me where I've screwed up? I thought this would be
    > > the easy part of this whole project I've been working on!

    >
    >
    >


  5. #5
    Bernie Deitrick
    Guest

    Re: Can't get simple macro to run

    Abi,

    It worked for me. Try setting the TakeFocusOnClick property of the button to
    False.

    HTH,
    Bernie
    MS Excel MVP

    "Abi" <[email protected]> wrote in message
    news:[email protected]...
    > I used the second suggestion (copied it in) and the button printed the

    first
    > page (Title Page) but then I got a run-time error for the rest. ???
    >
    > "Bernie Deitrick" wrote:
    >
    > > Private Sub CommandButton1_Click ( )
    > >
    > > PrintQuote
    > > End Sub
    > >
    > > and the code for the PrintQuote need to go into a standard codemodule,

    not
    > > the worksheet's codemodule.
    > >
    > > Or, you could simply use
    > >
    > > Private Sub CommandButton1_Click ( )
    > > Sheets("Title Page").Select
    > > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    > > Sheets(Array("Thankyou", "AV EQ", "QuoteSummary", "Terms", "Punch
    > > List")).Select
    > > Sheets("Thankyou").Activate
    > > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    > > End Sub
    > >
    > >
    > > HTH,
    > > Bernie
    > > MS Excel MVP
    > >
    > > "Abi" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Okay. Pretend I'm a totally idiot and and can't seem to get anything

    to
    > > work
    > > > right!
    > > >
    > > > Now, I have done a few macros before (basically just recording them

    and
    > > then
    > > > assigning them to controls - but have not done this in Excel before,

    so
    > > maybe
    > > > I'm missing something here). I don't know how to code at all.
    > > >
    > > > ALL I want to do is have a user click on one button and - viola - the

    > > macro
    > > > does its thing.
    > > >
    > > > The macro I have recorded prints several sheets in a workbook. It

    works.
    > > I
    > > > tried it out and it works.
    > > >
    > > > Here's what I've done so far.
    > > > 1 - recorded a macro to print pages.
    > > > 2 - created a button on one sheet. Right-clicked on it and selected

    View
    > > > Code.
    > > > 3 - I inserted my macro in the VB editor by opening up the macro and
    > > > copy/pasting it into the VB editor after:
    > > > Private Sub CommandButton1_Click ( )
    > > > End Sub
    > > > -------------------------------------------------------------
    > > > Sub PrintQuote()
    > > > '
    > > > ' PrintQuote Macro
    > > > ' Macro recorded 1/12/2005 by XXX
    > > > '
    > > >
    > > > '
    > > > Sheets("Title Page").Select
    > > > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    > > > Sheets(Array("Thankyou", "AV EQ", "QuoteSummary", "Terms", "Punch
    > > > List")).Select
    > > > Sheets("Thankyou").Activate
    > > > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    > > > End Sub
    > > >
    > > > Can someone please tell me where I've screwed up? I thought this

    would be
    > > > the easy part of this whole project I've been working on!

    > >
    > >
    > >




  6. #6
    Abi
    Guest

    Re: Can't get simple macro to run

    Well, I made the True/False change, and then started over and hand-typed the
    entire script over again...and it worked! (At least, it worked that time!)
    THANK YOU SO MUCH!!!!!!

    "Bernie Deitrick" wrote:

    > Abi,
    >
    > It worked for me. Try setting the TakeFocusOnClick property of the button to
    > False.
    >
    > HTH,
    > Bernie
    > MS Excel MVP
    >
    > "Abi" <[email protected]> wrote in message
    > news:[email protected]...
    > > I used the second suggestion (copied it in) and the button printed the

    > first
    > > page (Title Page) but then I got a run-time error for the rest. ???
    > >
    > > "Bernie Deitrick" wrote:
    > >
    > > > Private Sub CommandButton1_Click ( )
    > > >
    > > > PrintQuote
    > > > End Sub
    > > >
    > > > and the code for the PrintQuote need to go into a standard codemodule,

    > not
    > > > the worksheet's codemodule.
    > > >
    > > > Or, you could simply use
    > > >
    > > > Private Sub CommandButton1_Click ( )
    > > > Sheets("Title Page").Select
    > > > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    > > > Sheets(Array("Thankyou", "AV EQ", "QuoteSummary", "Terms", "Punch
    > > > List")).Select
    > > > Sheets("Thankyou").Activate
    > > > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    > > > End Sub
    > > >
    > > >
    > > > HTH,
    > > > Bernie
    > > > MS Excel MVP
    > > >
    > > > "Abi" <[email protected]> wrote in message
    > > > news:[email protected]...
    > > > > Okay. Pretend I'm a totally idiot and and can't seem to get anything

    > to
    > > > work
    > > > > right!
    > > > >
    > > > > Now, I have done a few macros before (basically just recording them

    > and
    > > > then
    > > > > assigning them to controls - but have not done this in Excel before,

    > so
    > > > maybe
    > > > > I'm missing something here). I don't know how to code at all.
    > > > >
    > > > > ALL I want to do is have a user click on one button and - viola - the
    > > > macro
    > > > > does its thing.
    > > > >
    > > > > The macro I have recorded prints several sheets in a workbook. It

    > works.
    > > > I
    > > > > tried it out and it works.
    > > > >
    > > > > Here's what I've done so far.
    > > > > 1 - recorded a macro to print pages.
    > > > > 2 - created a button on one sheet. Right-clicked on it and selected

    > View
    > > > > Code.
    > > > > 3 - I inserted my macro in the VB editor by opening up the macro and
    > > > > copy/pasting it into the VB editor after:
    > > > > Private Sub CommandButton1_Click ( )
    > > > > End Sub
    > > > > -------------------------------------------------------------
    > > > > Sub PrintQuote()
    > > > > '
    > > > > ' PrintQuote Macro
    > > > > ' Macro recorded 1/12/2005 by XXX
    > > > > '
    > > > >
    > > > > '
    > > > > Sheets("Title Page").Select
    > > > > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    > > > > Sheets(Array("Thankyou", "AV EQ", "QuoteSummary", "Terms", "Punch
    > > > > List")).Select
    > > > > Sheets("Thankyou").Activate
    > > > > ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    > > > > End Sub
    > > > >
    > > > > Can someone please tell me where I've screwed up? I thought this

    > would be
    > > > > the easy part of this whole project I've been working on!
    > > >
    > > >
    > > >

    >
    >
    >


+ 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