+ Reply to Thread
Results 1 to 5 of 5

print pdf's with changing filenames in a macro

  1. #1

    print pdf's with changing filenames in a macro

    I have created a macro to isolate certain data based on a variable
    loop. I would like to print the data to a pdf file. I was able to get
    it to print but it always uses the same filename; "Group" The
    following code in a k loop works to make fn$ the filename I desire; I
    checked it by sending the fn$ to sequential cells of a sheet.

    How can I get the pdf filename to change within the loop?
    Thanks for any help.
    Charlie




    s$ = Str(k)
    If k < 10 Then s$ = "0" & Right(s$, 1) Else s$ = Right(s$, 2)
    fn$ = "Group" & s$ & ".pdf"

    filename:=fn$
    ActiveWindow.SelectedSheets.PrintOut Copies:=1


  2. #2
    Tom Ogilvy
    Guest

    RE: print pdf's with changing filenames in a macro

    have you tried:


    ActiveWindow.SelectedSheets.PrintOut Copies:=1, PrintToFile:=True,
    PrToFileName:=fn$


    --
    Regards,
    Tom Ogilvy



    "[email protected]" wrote:

    > I have created a macro to isolate certain data based on a variable
    > loop. I would like to print the data to a pdf file. I was able to get
    > it to print but it always uses the same filename; "Group" The
    > following code in a k loop works to make fn$ the filename I desire; I
    > checked it by sending the fn$ to sequential cells of a sheet.
    >
    > How can I get the pdf filename to change within the loop?
    > Thanks for any help.
    > Charlie
    >
    >
    >
    >
    > s$ = Str(k)
    > If k < 10 Then s$ = "0" & Right(s$, 1) Else s$ = Right(s$, 2)
    > fn$ = "Group" & s$ & ".pdf"
    >
    > filename:=fn$
    > ActiveWindow.SelectedSheets.PrintOut Copies:=1
    >
    >


  3. #3

    Re: print pdf's with changing filenames in a macro

    Thanks, When I copied that to my macro, I got "Named argument not
    found" compile error and it highlighted "PrToFileName:=" in my code.
    Any ideas?


    Tom Ogilvy wrote:
    > have you tried:
    >
    >
    > ActiveWindow.SelectedSheets.PrintOut Copies:=1, PrintToFile:=True,
    > PrToFileName:=fn$
    >
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    >
    > "[email protected]" wrote:
    >
    > > I have created a macro to isolate certain data based on a variable
    > > loop. I would like to print the data to a pdf file. I was able to get
    > > it to print but it always uses the same filename; "Group" The
    > > following code in a k loop works to make fn$ the filename I desire; I
    > > checked it by sending the fn$ to sequential cells of a sheet.
    > >
    > > How can I get the pdf filename to change within the loop?
    > > Thanks for any help.
    > > Charlie
    > >
    > >
    > >
    > >
    > > s$ = Str(k)
    > > If k < 10 Then s$ = "0" & Right(s$, 1) Else s$ = Right(s$, 2)
    > > fn$ = "Group" & s$ & ".pdf"
    > >
    > > filename:=fn$
    > > ActiveWindow.SelectedSheets.PrintOut Copies:=1
    > >
    > >



  4. #4
    Tom Ogilvy
    Guest

    Re: print pdf's with changing filenames in a macro

    Your using xl97 or earlier? Because that argument is supported in xl2000
    and later.

    From xl2000 help on Printout
    expression.PrintOut(From, To, Copies, Preview, ActivePrinter, PrintToFile,
    Collate, PrToFileName)

    --
    Regards,
    Tom Ogilvy



    <[email protected]> wrote in message
    news:[email protected]...
    > Thanks, When I copied that to my macro, I got "Named argument not
    > found" compile error and it highlighted "PrToFileName:=" in my code.
    > Any ideas?
    >
    >
    > Tom Ogilvy wrote:
    >> have you tried:
    >>
    >>
    >> ActiveWindow.SelectedSheets.PrintOut Copies:=1, PrintToFile:=True,
    >> PrToFileName:=fn$
    >>
    >>
    >> --
    >> Regards,
    >> Tom Ogilvy
    >>
    >>
    >>
    >> "[email protected]" wrote:
    >>
    >> > I have created a macro to isolate certain data based on a variable
    >> > loop. I would like to print the data to a pdf file. I was able to get
    >> > it to print but it always uses the same filename; "Group" The
    >> > following code in a k loop works to make fn$ the filename I desire; I
    >> > checked it by sending the fn$ to sequential cells of a sheet.
    >> >
    >> > How can I get the pdf filename to change within the loop?
    >> > Thanks for any help.
    >> > Charlie
    >> >
    >> >
    >> >
    >> >
    >> > s$ = Str(k)
    >> > If k < 10 Then s$ = "0" & Right(s$, 1) Else s$ = Right(s$, 2)
    >> > fn$ = "Group" & s$ & ".pdf"
    >> >
    >> > filename:=fn$
    >> > ActiveWindow.SelectedSheets.PrintOut Copies:=1
    >> >
    >> >

    >




  5. #5

    Re: print pdf's with changing filenames in a macro

    Very close. I looked up "printout" in the help file. It says:

    PrintToFile Optional Variant. True to print to a file. Microsoft
    Excel prompts the user to enter the name of the output file. There's
    no way to specify the filename from Visual Basic. This option is not
    available on the Macintosh.

    I have a Mac with Office v.X

    I never figured it made a difference or I'd have mentioned it before.
    Any way to work around it?
    Thanks a lot for all of your help.
    Charlie



    Tom Ogilvy wrote:
    > Your using xl97 or earlier? Because that argument is supported in xl2000
    > and later.
    >
    > From xl2000 help on Printout
    > expression.PrintOut(From, To, Copies, Preview, ActivePrinter, PrintToFile,
    > Collate, PrToFileName)
    >
    > --
    > Regards,
    > Tom Ogilvy



+ 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