setting workbook variable

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

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

Setting a workbook variable

resolvedResolved · High Priority · Version 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:

Make macros work in newer versions of Excel

If 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.

To do this, go to Tools - Options - Security.

Select Macro Security and change the security setting to Low.

Tick the boxes next to 'Trust Add-ins' and 'Trust Visual Basic' and click OK.

After you have restarted Windows, you should then be able to use your macros created in earlier versions of Excel.

View all Excel hints and tips


Server loaded in 0.12 secs.