VBA InputBox syntax

Drrellik

Well-known Member
Joined
Apr 29, 2013
Messages
834
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2011
  5. 2010
Platform
  1. Windows
Hello all,

I have the following
Code:
Sub onopen()
Dim i As Integer
[U][I]
Dim myvalue As Variant   [/I][/U]

On Error GoTo invalid:

[I][U]myvalue = InputBox("Workbook Name?")[/U][/I]


' copy data from sheet called daily column B & Column G

Workbooks("daily.xls").Sheets(1).Range("B32:B99").Copy Destination:=ActiveWorkbook.Sheets("input").Range("Q2")

Workbooks("daily.xls").Sheets(1).Range("G32:G99").Copy Destination:=ActiveWorkbook.Sheets("input").Range("R2")


I want to replace Workbooks("daily.xls") with Workbooks("myvalue.xls") not sure how to do it.

Thanks Don
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
That's all it took.... thank you again for your quick response.
 
Upvote 0
That's all it took.... thank you again for your quick response.
The reason is because myvalue was a variable name... when you put it inside the quote marks, it told VB to just consider it a collection of unrelated characters... putting it outside of the quote marks let VB see it was not a text constant.
 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,155
Members
449,208
Latest member
emmac

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top