I have browsed this and other forums to create a code to accomplish this task. I have no previous VBA experience so please be gentle.
Essentially, what I would like to have happen is the user fills out the Excel form and clicks a button. The button will reference what was selected in cell K4 and then based off that selection, copy a hidden worksheet into a new workbook and then prompt the user to save.
The Code I am using is:
Private Sub RSM_Click()
Dim newWkbk As Workbook
Dim newWksht As Worksheet
Dim wksht As Worksheet
Dim test As String
If StrComp(Me.Range("K4").Text, "INTERNAL USB", vbTextCompare) = 0 Then
test = "RSM_InternalUSB"
ElseIf StrComp(Me.Range("K4").Text, "INTERNAL 24 HR", vbTextCompare) = 0 Then
test = "RSM_Internal24Hr"
Else
test = "RSM_External"
End If
For Each wksht In ThisWorkbook.Worksheets
If wksht.Name = test Then
wksht.Visible = xlSheetVisible
Set newWksht = wksht.Copy
newWksht.Name = "RSM Onboarding Guide"
Set newWkbk = newWksht.Parent
End If
Next wksht
Dim varResult As Variant
Dim ActBook As Workbook
'displays the save file dialog
varResult = Application.GetSaveAsFilename(FileFilter:= _
"Excel Files (*.xlsm), *.xlsm", Title:="RSM Guide", _
InitialFileName:="\\Onboarding\")
'checks to make sure the user hasn't canceled the dialog
If varResult <> False Then
ActiveWorkbook.SaveCopyAs Filename:=varResult
Exit Sub
End If
End Sub
However I am getting a
Compile error: Expected function or Variable
on the Set newwksht = wksht.Copy
strand. It doesn't like the copy.
I don't even know if the save portion will work as I haven't been able to get past this