This is a section of code that creates a folder named based on user input. It creates a backup file based on same input and saves in folder. It then proceeds with the rest of the code. I need to open backup file, edit, then re-run macro and allow it to save but it errors where indicated below.
'Sub CreateFolder()
Dim rootDirectory As String
Dim folderToBeCreated As String
Dim path As String
' Set the root directory path
rootDirectory = "C:\"
' give a valid name for folder
folderToBeCreated = "Program"
path = rootDirectory & folderToBeCreated
If Len(Dir(rootDirectory, vbDirectory)) <> 0 Then 'check if RootDirectory Exists?
If Len(Dir(path, vbDirectory)) = 0 Then ' full path should not exist already
VBA.MkDir ("C:\Program")
MsgBox "Folder created successfully"
Else
MsgBox "Folder already exists"
End If
Else
MsgBox "Root directory does not exist"
End If
'Create Input Box Function for User input of name for naming backup file
'Sub TournSaveBox()
'declare variable to hold value returned by InputBox
Dim myInputBoxVariable As String
Dim subjectVariable As String
subjectVariable = " ones input pre-Reg A"
'(1) create InputBox, and (2) assign value returned by InputBox function to variable
myInputBoxVariable = InputBox(Prompt:="Naming backup file", Title:="Saving ones ", Default:="Enter Name")
'display message box with value held by variable
MsgBox "name: " & myInputBoxVariable
VBA.MkDir ("C:\Program\") & myInputBoxVariable & "" **** ERRORS HERE *******************************************************
MsgBox "Folder created successfully"
ActiveWorkbook.SaveAs Filename:="C:\Program\" & myInputBoxVariable & "\" & myInputBoxVariable & subjectVariable & ".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
'ActiveWindow.SmallScroll Down:=-15
'Sub CreateFolder()
Dim rootDirectory As String
Dim folderToBeCreated As String
Dim path As String
' Set the root directory path
rootDirectory = "C:\"
' give a valid name for folder
folderToBeCreated = "Program"
path = rootDirectory & folderToBeCreated
If Len(Dir(rootDirectory, vbDirectory)) <> 0 Then 'check if RootDirectory Exists?
If Len(Dir(path, vbDirectory)) = 0 Then ' full path should not exist already
VBA.MkDir ("C:\Program")
MsgBox "Folder created successfully"
Else
MsgBox "Folder already exists"
End If
Else
MsgBox "Root directory does not exist"
End If
'Create Input Box Function for User input of name for naming backup file
'Sub TournSaveBox()
'declare variable to hold value returned by InputBox
Dim myInputBoxVariable As String
Dim subjectVariable As String
subjectVariable = " ones input pre-Reg A"
'(1) create InputBox, and (2) assign value returned by InputBox function to variable
myInputBoxVariable = InputBox(Prompt:="Naming backup file", Title:="Saving ones ", Default:="Enter Name")
'display message box with value held by variable
MsgBox "name: " & myInputBoxVariable
VBA.MkDir ("C:\Program\") & myInputBoxVariable & "" **** ERRORS HERE *******************************************************
MsgBox "Folder created successfully"
ActiveWorkbook.SaveAs Filename:="C:\Program\" & myInputBoxVariable & "\" & myInputBoxVariable & subjectVariable & ".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
'ActiveWindow.SmallScroll Down:=-15