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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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,216,101
Messages
6,128,842
Members
449,471
Latest member
lachbee

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