Dear All,
I created a button on a userform to print an offer document.
I us the userform to insert the offer proposition number and to select the language to print out the document.
Once i push the print button on the userform, i would like:
- the offer document printed as PDF in the selected language(s) and saved in a folder
- the complete excel document saved as xlsm in the same folder
I wrote a formula in vba, based on what i found on internet, because it's the first time that i use VBA or anything like it.
The button does already 90% of what it should ;-)
But i have problems with the 2 last item that i want to add to the formula.
1.Save the complete excel document as xlsm in the same folder.
2.When i use the print button and the proposition already exists, the old document gets overwritten. Isn't it possible to check the folder for existing file names and pop up a message box when the file name already exists. So that the action is not carried out, but that you are required to enter another number.
Can someone help me, please?
This is the formula that i wrote:
P
rivate Sub CommandButton1_Click()
pname = ThisWorkbook.Path
Number = TextBox1.Text
Installer = Blad1.Range("B2").Text
Client = Blad1.Range("G2").Text
typ = Blad1.Range("A16").Text
If TextBox1.Text = "" Then
MsgBox "No proposition number given!", vbOKOnly, "Error Proposition"
ElseIf CheckBox1.Value = False And CheckBox2.Value = False And CheckBox3.Value = False Then
MsgBox "No language selected!", vbOKOnly, "Error Language"
ElseIf CheckBox1.Value = True Then
Sheets("Offer NL").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\offer\" & Number & " - " & Installer & " - " & Client & " - " & typ & (" NL ") & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
UserForm1.Hide
End If
If CheckBox2.Value = True Then
Sheets("Offer FR").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\offer\" & Number & " - " & Installer & " - " & Client & " - " & typ & (" FR ") & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
UserForm1.Hide
End If
If CheckBox3.Value = True Then
Sheets("Offer ENG").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\offer\" & Number & " - " & Installer & " - " & Client & " - " & typ & (" ENG ") & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
UserForm1.Hide
End If
Sheets("Main data").Select
End Sub
Bookmarks