Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

setting workbook variable

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Setting a workbook variable

Setting a workbook variable

ResolvedVersion 2007
Edited on Sun 25 Nov 2012, 18:38

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 courses

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Finding cells that have data restrictions

Click anywhere on the worksheet.
On the Edit menu, click Go To.
Click Special.
Click Data validation.
Click All.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.