declaring workbook names

bsquad

Board Regular
Joined
Mar 15, 2016
Messages
194
I am having some trouble with this code and know it's most probably an easy little syntax I am missing. the 'FileNameR' is text in a cell of the full workbook name including the file extension. I have also tried declaring it as a string (besides the variant). The error is coming on 'InaWB' with a runtime error 13 Type mismatch. - guessing why its a simple syntax thing I am missing.


Code:
Dim FileNameR As Variant
            FileNameR = ThisWorkbook.Sheets("Sheet1").Range("O4", ThisWorkbook.Sheets("Sheet1").Range("O4").End(xlDown)).Value
    Dim InaWB As Workbook
        Set InaWB = Workbooks(FileNameR)
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hello bsquad,

You are trying to use a Variant Array (FileNameR) as a String. This will not work.

Which cell or cells in the column "O" are of interest?
 
Upvote 0
Hi Leith,

as I really appreciate the response; I did figure out an alternative method. It turns out I had something similar in another workbook.
-I created sort of a history log of the code runtimes. The files that you can import can be dynamic in the naming. So each time it runs, it dumps the file name in a different last row scenario for column "O".

Code:
Dim LR As Long
        LR = ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, "O").End(xlUp).Row
    Dim FileNameR As String
        FileNameR = ThisWorkbook.Sheets("Sheet1").Cells(LR, 15).Value
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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