record the filename of wkb2

andymalan

Board Regular
Joined
Feb 22, 2017
Messages
128
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
Dear Friends, I have searched and read many similar posts, but nothing currently fits for me. Your help will be greatly appreciated.

My code opens a directory allowing the user to select a file to work with. I need code that will copy the filename of wkb2 and paste it to the workbook ("FactoryDrawingConfig.xlsm") that holds the code.
code<>
'Opens the csv directory and shows files to select from
Dim wkb2 As Workbook
Dim Usersname As String
Usersname = Environ("USERNAME")
strFileName = "C:\Users\" & Usersname & _
"\Dropbox\PC\Documents\CapitalElement\FilesToConvert"
ChDir strFileName
FileFilter = "Excel 2003 (*.xls),*.xls," & _
"Excel 2007 > (*.xlsx),*.xlsx," & _
"All Excel Files (*.xl*),*.xl*," & _
"All Files (*.*),*.*"
strFileName = Application.GetOpenFilename(FileFilter, 4, "Select One File To Open")
Set wkb2 = Workbooks.Open(strFileName, False, False)
<>
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
There is no copy and paste for the workbook name.
VBA Code:
'start
dim wb as workbook
set wb=thisworkbook 'thisworkbook is the workbook with the code

'end
'wherever you want the wbk2 name
wb.worksheets("Sheet1").range("A1")=wbk2.name
 
Upvote 0
There is no copy and paste for the workbook name.
VBA Code:
'start
dim wb as workbook
set wb=thisworkbook 'thisworkbook is the workbook with the code

'end
'wherever you want the wbk2 name
wb.worksheets("Sheet1").range("A1")=wbk2.name
 
Upvote 0
Hello Dave
thanks for your prompt reply. Unfortunately, I get an error "Object Required" when I run the code. what have I done wrong?

1658916818612.png
 
Upvote 0

Forum statistics

Threads
1,215,013
Messages
6,122,694
Members
449,092
Latest member
snoom82

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