98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Setting a workbook variable
Setting a workbook variable
Resolved · High Priority · Version 2007
Louisa has attended:
Excel VBA Intro Intermediate course
Excel VBA Advanced course
Setting a workbook variable
I HAVE MANAGED TO RESOLVE THIS PLEASE IGNORE
I have searched far and wide over google and can't find the answer.
I have a variable workbook name. I am checking with an input box that the workbook is open and then want to use it once it has been open. I know I could check if it was open but would rather the user (who will usually be me) does it before running the macro.
I get a compile error : type mismatch on the workbook variable when I try to set it.
Thanks in advance. I am pulling my hair out over this. I am sure its just something small I am missing but can't figure it out.
Here is the code
Sub InputDash()
dteWorking = Worksheets("date").Range("e14")
strWorking = Format(dteWorking, "dd mmmm")
strPath = ThisWorkbook.Path
strDash = InputBox("Have you saved the latest dashboad and is it open", _
"Dashboard", "Type Yes or No here")
If strDash = "No" Then
MsgBox ("Make sure latest Dashboard is open before trying again")
Exit Sub
End If
Set wbkDash = ("Dashboard " & strworking & "xlsm")
Workbooks(wbkDash).Worksheets("front sheet").Range("a1").Select
End Sub
I have also tried to set the workbook name as a string and can't get that to work either.
Sub InputDash()
dteWorking = Worksheets("date").Range("e14")
strWorking = Format(dteWorking, "dd mmmm")
strPath = ThisWorkbook.Path
strDashName = ("Dashboard " & strWorking & ".xlsm")
strDash = InputBox("Have you saved the latest dashboad and is it open", _
"Dashboard", "Type Yes or No here")
If strDash = "No" Then
MsgBox ("Make sure latest Dashboard is open before trying again")
Exit Sub
End If
'Set wbkDash = ("Dashboard 23 November.xlsm")
Workbooks(strDashName).Worksheets("front sheet").Range("a1").Select
End Sub
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Make macros work in newer versions of ExcelIf you have created macros in Excel 97 or 2000 that you want to be able to use in 2002/XP or 2003, you may need to alter the macro security settings in the newer version of Excel you are using. |