Steven_Smith
New Member
- Joined
- Apr 5, 2016
- Messages
- 4
Hi All,
Long time user, first time poster here. I put that down to may other people having the issues I have before I do and then the Gurus here sorting them out in a very well written way so thanks for that.
I however have an issue I have been unable to find the resolution to. I recently wrote a sub procedure which is called by Workbook_Open(). It was meant to create a new copy of the file on the users PC, so that they didn't end up overwriting my template on SharePoint (they couldn't anyway as they only have read-only rights, but they want it to be straightforward into editing).
So, the macro creates an editable copy of the template with a new name based on a reference number that they provide via an input box and then saves to the desktop. I then switch all the application switches back to normal and try to save again so they don't end up opening and finding task bars missing, etc. However, when the final save happens it throws out Run Time Error '91' : Object Variable or With Block not Set.
Any ideas?
Long time user, first time poster here. I put that down to may other people having the issues I have before I do and then the Gurus here sorting them out in a very well written way so thanks for that.
I however have an issue I have been unable to find the resolution to. I recently wrote a sub procedure which is called by Workbook_Open(). It was meant to create a new copy of the file on the users PC, so that they didn't end up overwriting my template on SharePoint (they couldn't anyway as they only have read-only rights, but they want it to be straightforward into editing).
So, the macro creates an editable copy of the template with a new name based on a reference number that they provide via an input box and then saves to the desktop. I then switch all the application switches back to normal and try to save again so they don't end up opening and finding task bars missing, etc. However, when the final save happens it throws out Run Time Error '91' : Object Variable or With Block not Set.
Any ideas?
Code:
Sub SavetoPC()
iceRef = InputBox("Which ICE/CR reference is this extraction pack for?")
If iceRef = "" Then
MsgBox ("You have failed to enter a valid ICE reference, this workbook will now close")
Application.ThisWorkbook.Close SaveChanges:=False
End If
With Application
.Calculation = xlCalculationManual
.DisplayAlerts = False
.DisplayStatusBar = False
.EnableAnimations = False
.EnableEvents = False
.ScreenUpdating = False
End With
ThisWorkbook.Worksheets("JobPack").Range("B3").Value = iceRef
DTAdd = CreateObject("WScript.Shell").specialfolders("Desktop")
fileName = iceRef + "_ExtractionPack"
fullPath = DTAdd + "\" + fileName + ".xlsm"
ChDir DTAdd
ThisWorkbook.SaveAs fileName:=fullPath, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
With Application
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
.DisplayStatusBar = True
.EnableAnimations = True
.EnableEvents = True
.ScreenUpdating = True
End With
ActiveWorkbook.Save
End Sub