I am trying to paste a hyperlink using a send key function. Problem is, the sendkey function will not work if I try to close the workbook I copied from. The code is below
Private Sub CommandButton1_Click()
Dim linkedsht As String
'if selected sheet was not changed or rates was selected, exit out
linkedsht = UserForm1.ComboBox1.Value
If linkedsht = "Choose a tab" Then
MsgBox "Please choose a tab"
Exit Sub
End If
If linkedsht = "Rates" Then
MsgBox "Rates tab is not an option, please choose another tab"
UserForm1.ComboBox1.Value = "Choose a tab"
Exit Sub
End If
'copy from the selected workbook and then go to template and paste hyperlink
Workbooks(TempBook).Sheets(linkedsht).Range("a1").Copy
Windows(MainBook).Activate
Sheets(Mainsht).Range(TargetCell).Select
Application.SendKeys "%(eh)", True
'Reset Userform and close tempbook
UserForm1.ComboBox1.Value = "Choose a tab"
UserForm1.Hide
Windows(TempBook).Close False '___the link will not paste with this here
End Sub
Private Sub CommandButton1_Click()
Dim linkedsht As String
'if selected sheet was not changed or rates was selected, exit out
linkedsht = UserForm1.ComboBox1.Value
If linkedsht = "Choose a tab" Then
MsgBox "Please choose a tab"
Exit Sub
End If
If linkedsht = "Rates" Then
MsgBox "Rates tab is not an option, please choose another tab"
UserForm1.ComboBox1.Value = "Choose a tab"
Exit Sub
End If
'copy from the selected workbook and then go to template and paste hyperlink
Workbooks(TempBook).Sheets(linkedsht).Range("a1").Copy
Windows(MainBook).Activate
Sheets(Mainsht).Range(TargetCell).Select
Application.SendKeys "%(eh)", True
'Reset Userform and close tempbook
UserForm1.ComboBox1.Value = "Choose a tab"
UserForm1.Hide
Windows(TempBook).Close False '___the link will not paste with this here
End Sub