Filename = Dir(Path) is not giving me the full name

ds2020

New Member
Joined
Mar 15, 2020
Messages
16
Office Version
  1. 2019
Platform
  1. Windows
this is part of my code to open multiple workbooks and put them in sheets in one workbook. However, the name (path) is not the full path (it's missing the important part of the names). What can I do to get the full name of every sheet from this code?



Path = "D:\uni\Test Data\197\New folder\"
Filename = Dir(Path)

Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy after:=ThisWorkbook.Sheets(1)
Next Sheet
Workbooks(Filename).Close
Filename = Dir()
Loop

Dim xsheet As Worksheet
For Each xsheet In ThisWorkbook.Worksheets
xsheet.Select
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
How about
VBA Code:
 Filename = Dir(Path & "*.xls*")
 
Upvote 0
In what way?
Do you get any errors, do the files open, does nothing open?
 
Upvote 0
What problem?
The name of each workbook is not the full name

photo_2020-06-15_16-38-32.jpg
photo_2020-06-15_16-38-41.jpg


It's missing a part the name after Unknown road
 
Upvote 0
What has a formula in a cell, got to do with your original question?
As yet you have not said what exactly is wrong.
Do you get any errors?
Do the workbooks get opened?
Do all the sheets in each workbook get copied?
WHAT? Please be specific.
 
Upvote 0
Everything Works. So this code is supposed to open multiple workbooks and copy each of them in a separate sheet in another workbook. But when it does that, the name of each workbook (now worksheet) is shorter. So the problem is the filename, it doesn't appear in full and I don't.
 
Upvote 0
Ok, I got you. There is nothing wrong with the code, or what it's doing, it's just that sheet names are limited to 31 characters. So you will need to get rid of part of the name.
How do you want it named?
Also are those csv files your opening?
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,048
Members
449,206
Latest member
Healthydogs

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