Consulting

Results 1 to 8 of 8

Thread: Save active sheet only as pdf + Increment the invoice number + print active sheet

  1. #1
    VBAX Newbie
    Joined
    Aug 2017
    Posts
    4
    Location

    Save active sheet only as pdf + Increment the invoice number + print active sheet

    Dear,

    I am having issues with macro in Excel 2011 for MAc.

    I am trying to save "Invoice" sheet as pdf (name "c5"+"E2") + Increment the invoice number in "E2" + print 2 copies of same sheet. Is it possible?

    My code is:

    Sub SaveInvoicePrint ()
     
    ' Print 
     
        ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=2
       
     
    Dim NewFN As Variant
        ' Create the PDF First
        NewFN = "Macintosh HD:Users:Erik 1:Desktop:Brin:Racuni2017:RacunAvt017:" & Range (“C5”).Value & Range("E2").Value & ".pdf"
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFN, _
            Quality:=xlQualityStandard, IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, OpenAfterPublish:=False
       
        ' Increment the invoice number
        Range("E2").Value = Range("E2").Value + 1
    End Sub
    Can you please help solve issue?! I am getting error. What am I doing wrong?

    Thank you in advance!!

  2. #2
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    Have you tried the obvious way:
    just use a bit of copy and paste in the code ( i haven't tested this)

    Sub SaveInvoicePrint () 
         
         ' Print
         
        ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1 
         
         
        Dim NewFN As Variant 
         ' Create the PDF First
        NewFN = "Macintosh HD:Users:Erik 1:Desktop:Brin:Racuni2017:RacunAvt017:" & Range (“C5”).Value & Range("E2").Value & ".pdf" 
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFN, _ 
        Quality:=xlQualityStandard, IncludeDocProperties:=True, _ 
        IgnorePrintAreas:=False, OpenAfterPublish:=False 
         
         ' Increment the invoice number
        Range("E2").Value = Range("E2").Value + 1 
    
    
        ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1 
         
         
        Dim NewFN As Variant 
         ' Create the PDF First
        NewFN = "Macintosh HD:Users:Erik 1:Desktop:Brin:Racuni2017:RacunAvt017:" & Range (“C5”).Value & Range("E2").Value & ".pdf" 
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFN, _ 
        Quality:=xlQualityStandard, IncludeDocProperties:=True, _ 
        IgnorePrintAreas:=False, OpenAfterPublish:=False 
         
         ' Increment the invoice number
    End Sub

  3. #3
    VBAX Newbie
    Joined
    Aug 2017
    Posts
    4
    Location
    I just tried. I got Compile Error...

  4. #4
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    Deletethe "Dim Newfn as variant" where is occurs for the second time, that will cause a compile error
    sorry.

  5. #5
    VBAX Newbie
    Joined
    Aug 2017
    Posts
    4
    Location
    Now i get error 1004:

    Method "Range" object "_Global" failed

    When debug this line is yellow: NewFN = "Macintosh HD:Users:Erik 1esktop:Brin:Racuni2017:RacunAvt017:" & Range(“C5”).Value & Range("E2").Value & ".pdf"

  6. #6
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    Hi, unfortunately I am not familiar with mac 2011 veriosn but what I would do is go back to your original code and jsut call it twice by running the loopprint macrolike thius:

    sub loopprint
     for i = 1 to 2
       call saveinvoicePrint
             ' Increment the invoice number
        Range("E2").Value = Range("E2").Value + 1 
     next i     
    end sub
    
    Sub SaveInvoicePrint () 
         
         ' Print
         
        ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1 
         
         
        Dim NewFN As Variant 
         ' Create the PDF First
        NewFN = "Macintosh HD:Users:Erik 1:Desktop:Brin:Racuni2017:RacunAvt017:" & Range (“C5”).Value & Range("E2").Value & ".pdf" 
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=NewFN, _ 
        Quality:=xlQualityStandard, IncludeDocProperties:=True, _ 
        IgnorePrintAreas:=False, OpenAfterPublish:=False 
         
    End Sub

  7. #7
    VBAX Newbie
    Joined
    Aug 2017
    Posts
    4
    Location
    Your first solution works. I have had wrong quotation marks :/

    The only problem is that it saves twice with two following numbers. In C5 i have name and in E2 i have number. So it saves for exampe erik123 and erik124 in two different files. I need just first, of course...

    Any other idea?

    Thanks!

  8. #8
    VBAX Expert
    Joined
    May 2016
    Posts
    604
    Location
    I am not clear what you want.

Tags for this Thread

Posting Permissions

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