PDA

View Full Version : Save invoice problem



smarko1983
10-10-2013, 09:29 AM
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.
10684

Kenneth Hobs
10-10-2013, 09:42 AM
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.

smarko1983
10-10-2013, 10:33 AM
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.
10685

Kenneth Hobs
10-10-2013, 11:17 AM
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