Save copy of an open Workbook and make pdf for archive

vvujke

New Member
Joined
Apr 27, 2012
Messages
3
Hi,

sorry for the code, couldn't make it work with VB HTML Maker. I'm new with VBA :) Basically my idea is when someone open default file, insert data, try to save file, macros save workbook with inserted data as another file (*.xlsx) and make pdf in another folder. Pdf part is working fine and i'll leave it here if someone can use it (i've saw couple of threads with this enquiries), but with second part just can't find right option

Pdf part

Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Dim Name As String
Dim i As Integer, j As Integer

Name = ThisWorkbook.Path & "\PDF Archive\" & ActiveSheet.Range("F6") & " Invoice " & ActiveSheet.Range("B11")
If Dir(Name & ".pdf") <> "" Then
If Dir(Name & " copy.pdf") <> "" Then
i = 1
j = 1
Do While i = 1
If Dir(Name & " copy (" & CStr(j) & ").pdf") <> "" Then
j = j + 1
i = 1
Else
i = 2
End If
Loop
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Name & " copy (" & CStr(j) & ").pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
End If
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Name & " copy" & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
End If
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Name & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False

End Sub

Excel part

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim ActSheet As Worksheet
Dim ActBook As Workbook
Dim CurrentFile As String
Dim NewFileType As String
Dim NewFile As String

Application.ScreenUpdating = False ' Prevents screen refreshing.

CurrentFile = ThisWorkbook.FullName

NewFileType = "Excel Files 2007 (*.xlsx), *.xlsx," & _
"Excel Files 1997-2003 (*.xls), *.xls," & _
"All files (*.*), *.*"


NewFile = Application.GetSaveAsFilename( _
InitialFileName:=ThisWorkbook.Path & "\" & ActiveSheet.Range("F6") & " Invoice " & ActiveSheet.Range("B11") & ".xlsx", _
fileFilter:=NewFileType)


If NewFile <> "" And NewFile <> "False" Then
ActiveWorkbook.SaveAs Filename:=NewFile, _
FileFormat:=51, _
Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False
Application.DisplayAlerts = False
Set ActBook = ActiveWorkbook
Workbooks.Open CurrentFile
ActBook.Close
End If

Application.ScreenUpdating = True
End Sub


Thanks guys for your time
P.S Sorry if i've made any language mistake
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,215,365
Messages
6,124,513
Members
449,168
Latest member
CheerfulWalker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top