Consulting

Results 1 to 4 of 4

Thread: Save invoice problem

  1. #1

    Question Save invoice problem

    Ok, so the invoice.xlsm file works fine, I have some "dummy" client names on the clientnames sheet, when I click on the "Save Invoice" it saves it in a folder. Now the problem starts when I copy the (real) data from client list.xlsx file into the invoice.xlsm file (in the clientnames sheet). I get the "The file could not be accessed. Try one of the following: -Make sure the specified folder exists...." error. I have no idea what is wrong.
    Invoice.xlsm

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Welcome to the forum!

    I only know English so I can not help much. Try something like this:
    Dim fn as String
    fn = "c:\temp"
    Msgbox Dir(fn, vbDirectory) <> ""
    This tests to see if the folder exists. In other words, test for the folder before you concatenate the strings for the filename to it.

  3. #3
    Quote Originally Posted by Kenneth Hobs View Post
    Welcome to the forum!

    I only know English so I can not help much. Try something like this:
    Dim fn as String
    fn = "c:\temp"
    Msgbox Dir(fn, vbDirectory) <> ""
    This tests to see if the folder exists. In other words, test for the folder before you concatenate the strings for the filename to it.
    Thanks for the reply Kenneth. I tried your code, the folder exists. I reuploaded the invoice and I translated important fields of the invoice to english so you can see what's going on.
    Invoice1.xlsm

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    You have a few other problems. To see the format for saving, try recording a macro. The other problem is in the makeup of the filename. In Windows, "/" and "\" are paths to folders. When using dates with slash characters, either use Format() to reformat the date to a string or Replace() to replace a string's characters that cause the problem.

    Use F8 to debug code one line at a time. Another way is by debug.print and view code in the Immediate Window. e.g.

    Sub SaveInvWithNewName()
      Dim NewFn As Variant, pDT As String
      'Copy invoice to a new workbook
      'ActiveSheet.Copy
      
      pDT = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator
      If Dir(pDT) = "" Then
        MsgBox "Path does not exist:" & vbLf & pDT, vbExclamation, "Macro Ending"
        Exit Sub
      End If
      NewFn = "C:\Users\nebojsa\Desktop\FakturaKraj\Fakt" & "--" & Range("F11").Value & "--" & Range("F15").Value & "--" & Range("F16").Value & ".xlsx"
      
      Debug.Print NewFn
      Exit Sub
      
      ActiveWorkbook.SaveAs NewFn, FileFormat:=xlOpenXMLWorkbook
      ActiveWorkbook.Close
      NextInvoice
    End Sub

Posting Permissions

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