Uploaded February 2020 | Updated September 2026, 2 weeks ago
How to automate the process of saving an existing file as a new version so that it is not overwritten.
Here's the complete VBA code:
Option Explicit
Sub SaveFileAsNewVersion()
Dim myFolderPath As String
Dim myPath As String
Dim Savename As String
Dim myVersion As String
Dim saveext As String
Dim Saved As Boolean
Dim i As Long
Dim Teststr As String
Dim myFileName As String
Dim myarray As Variant
Teststr = ""
Saved = False
i = 1
'version marker
myVersion = "_ver"
'Get info about our existing file
On Error GoTo NotYetSaved
myPath = ActiveWorkbook.FullName
myFileName = Mid(myPath, InStrRev(myPath, "\") + 1, InStrRev(myPath, ".") - InStrRev(myPath, "\") - 1)
myFolderPath = Left(myPath, InStrRev(myPath, "\"))
saveext = "." & Right(myPath, Len(myPath) - InStrRev(myPath, "."))
On Error GoTo 0
If InStr(1, myFileName, myVersion) NOTGREATERTHAN(Use Symbol)= 1 Then
myarray = Split(myFileName, myVersion)
Savename = myarray(0)
Else
Savename = myFileName
End If
If FileExist(myFolderPath & Savename & saveext) = False Then
ActiveWorkbook.SaveAs myFolderPath & Savename & saveext
Exit Sub
End If
Do While Saved = False
If FileExist(myFolderPath & Savename & myVersion & i & saveext) = False Then
ActiveWorkbook.SaveAs myFolderPath & Savename & myVersion & i & saveext
Saved = True
Else
i = i + 1
End If
Loop
Exit Sub
NotYetSaved:
MsgBox "This file has never been saved." & _
"Therefore cannot save as a new version!", vbCritical, "Not saved!"
End Sub
Function FileExist(FilePath As String) As Boolean
'Reference: http://www.rondebruin.nl/win/s9/win003.htm
Dim Teststr As String
On Error Resume Next
Teststr = Dir(FilePath)
On Error GoTo 0
If Teststr = "" Then
FileExist = False
Else
FileExist = True
End If
End Function
You can also refer to the website link for more ideas: exceltrainingvideos.com/automate-saving-new-file-version
How to automate the process of saving an existing file as a new version so that it is not overwritten.
Here's the complete VBA code:
Option Explicit
Sub SaveFileAsNewVersion()
Dim myFolderPath As String
Dim myPath As String
Dim Savename As String
Dim myVersion As String
Dim saveext As String
Dim Saved As Boolean
Dim i As Long
Dim Teststr As String
Dim myFileName As String
Dim myarray As Variant
Teststr = ""
Saved = False
i = 1
'version marker
myVersion = "_ver"
'Get info about our existing file
On Error GoTo NotYetSaved
myPath = ActiveWorkbook.FullName
myFileName = Mid(myPath, InStrRev(myPath, "\") + 1, InStrRev(myPath, ".") - InStrRev(myPath, "\") - 1)
myFolderPath = Left(myPath, InStrRev(myPath, "\"))
saveext = "." & Right(myPath, Len(myPath) - InStrRev(myPath, "."))
On Error GoTo 0
If InStr(1, myFileName, myVersion) NOTGREATERTHAN(Use Symbol)= 1 Then
myarray = Split(myFileName, myVersion)
Savename = myarray(0)
Else
Savename = myFileName
End If
If FileExist(myFolderPath & Savename & saveext) = False Then
ActiveWorkbook.SaveAs myFolderPath & Savename & saveext
Exit Sub
End If
Do While Saved = False
If FileExist(myFolderPath & Savename & myVersion & i & saveext) = False Then
ActiveWorkbook.SaveAs myFolderPath & Savename & myVersion & i & saveext
Saved = True
Else
i = i + 1
End If
Loop
Exit Sub
NotYetSaved:
MsgBox "This file has never been saved." & _
"Therefore cannot save as a new version!", vbCritical, "Not saved!"
End Sub
Function FileExist(FilePath As String) As Boolean
'Reference: http://www.rondebruin.nl/win/s9/win003.htm
Dim Teststr As String
On Error Resume Next
Teststr = Dir(FilePath)
On Error GoTo 0
If Teststr = "" Then
FileExist = False
Else
FileExist = True
End If
End Function
You can also refer to the website link for more ideas: exceltrainingvideos.com/automate-saving-new-file-version




![Whatsapp Desktop Automation with VBA
How to automate Whatsapp Desktop to login, search for user, send message and attachment and logout.
Heres the complete macro or VBA code:
Option Explicit
Dim driver As New WebDriver
Sub LoginSearchUserSendMessageAttachmentViaWhatsapp()
Chrome Driver
Selenium
Selenium Wrapper
Dim keys As New SeleniumWrapper.keys
Dim filepath As String
filepath = C:exceltrainingvideos-12find-header-with-todays-date.xlsm
driver.Start chrome
driver.Get https://web.whatsapp.com/
driver.Window.Maximize
driver.Wait 5000
driver.Wait 2000
driver.FindElementByXPath(//span[@title = Dt]).Click
driver.Wait 1000
driver.SendKeys (keys.Tab + keys.Tab)
driver.Wait 1000
driver.SendKeys (Poonam Mobile)
driver.Wait 1000
driver.SendKeys (keys.Enter)
driver.FindElementByClass (_3FRCZ)
driver.SendKeys (Please study *the below attached file* for the class tomorrow.)
driver.Wait 1000
driver.SendKeys (keys.Enter)
driver.Wait 2000
driver.FindElementByXPath(//div[@title=Attach]).Click
driver.Wait 10000
driver.FindElementByXPath(//input[@accept=image/*,video/mp4,video/3gpp,video/quicktime]).SendKeys (filepath)
driver.Wait 2000 this wait time depends on the size of your file max 64 mb
driver.FindElementByXPath(//span[@data-icon = send]).Click
driver.Wait 1000
driver.FindElementByXPath(//div[@title = Menu]).Click
driver.FindElementByXPath(//div[@title=Log out]).Click
driver.Quit
End Sub Whatsapp Desktop Automation with VBA](https://i.ytimg.com/vi/kYcbEGYCABE/mqdefault.jpg)





