Consulting

Results 1 to 7 of 7

Thread: VBA Excel increase invoice number and save (need help with code) Excel 2003

  1. #1
    VBAX Regular
    Joined
    Jul 2016
    Posts
    6
    Location

    Question VBA Excel increase invoice number and save (need help with code) Excel 2003

    Private Sub Workbook_Open()
    Application.WindowState = xlMaximized
    End Sub
    
    Sub NextInvoice()
     Sheets("InvoiceB").Range("F5").Value = Sheets("InvoiceB").Range("F5").Value + 1
    'Range(“A20:E39”).ClearContents
    End Sub
    
    Sub SaveInvWithNewName()
    Dim NewFN As Variant
    ActiveSheet.Copy
    NewFN = “C:aaaInv” & Range(“F5”).Value & “.xls” '<-get compile error here not sure why?
    ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
    ActiveWorkbook.Close
    NextInvoice
    End Sub

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Your quotation marks are the "wrong type"; just replace them. Also, I think your missing "\" here. "C:aaaInv"
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Jul 2016
    Posts
    6
    Location
    Private Sub Workbook_Open()
    Application.WindowState = xlMaximized
    End Sub
    
    Sub NextInvoice()
    Sheets("InvoiceB").Range("F5").Value = Sheets("InvoiceB").Range("F5").Value + 1
    End Sub
    
    Sub SaveInvWithNewName()
    Dim NewFN As Variant
    ActiveSheet.Copy
    NewFN = "C:\invoices\Inv" & Range("F5").Value & ".xlsx"
    ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
    ActiveWorkbook.Close
    NextInvoice
    End Sub

    Get error 400 not sure why my guess is 2003 can't save that type of format , does 2003 have non macro save format?
    Last edited by Galdorf; 07-06-2016 at 01:00 PM.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    does 2003 have non macro save format?
    No, Just save as xls.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Regular
    Joined
    Jul 2016
    Posts
    6
    Location
    Quote Originally Posted by mdmackillop View Post
    does 2003 have non macro save format?
    No, Just save as xls.
    so
    Sub SaveInvWithNewName()
    Dim NewFN As Variant
    ActiveSheet.Copy
    NewFN = "C:\invoices\Inv" & Range("F5").Value & ".xls"
    ActiveWorkbook.SaveAs NewFN, FileFormat:=xlWorkbookNormal
    ActiveWorkbook.Close
    NextInvoice
    End Sub

    should work?

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Looks OK, I don't believe the FileFormat is necessary.

    Does the code need to work for more than one person? If so, you should look at saving the Invoice number in a separate file.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Regular
    Joined
    Jul 2016
    Posts
    6
    Location
    Quote Originally Posted by mdmackillop View Post
    Looks OK, I don't believe the FileFormat is necessary.

    Does the code need to work for more than one person? If so, you should look at saving the Invoice number in a separate file.
    Only going to be used by one person although the file i save should be read only not sure how to do that in excel 2003 i should also make function to print 2 copies of invoice as well not sure how to do that.

Posting Permissions

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