PDA

View Full Version : vba code for getting the filename for another worksheet on a newfile worksheet



jessmendez01
05-04-2016, 01:00 PM
Below is the code i have where it opens from my directory and opens a workbook...i need that file name and path to report back to my 4-26-16 testing2.xlsm file in column A

What am i doing wrong b/c it's not doing it


Option Explicit


Sub Filename()

Dim originalFile As String
Dim NewFile As String
originalFile = ActiveWorkbook.name
NewFile = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls*), *.xls", Title:="Please select a file", MultiSelect:=False) 'only excel files
Workbooks.Open NewFile
NewFile = Dir(NewFile)

ActiveCell = ActiveWorkbook.FullName
Range("A" & ActiveCell.Row).Select: Workbook "4-26-16 testing2.xlsm"

End Sub

Kenneth Hobs
05-04-2016, 02:25 PM
I already explained how to do it in your other thread. http://www.vbaexpress.com/forum/showthread.php?55926-VBA-export-filename-and-path

You are still not posting code betwee code tags. Click the # icon on the reply toolbar to insert the codes as I explained.

What you have added here is a workbook name. Is this workbook (4-26-16 testing2.xlsm) open already? Where does the macro code go, in a 3rd workbook or the 4-26-16 testing2.xlsm which is open or not?

When you say file in column A, I am not sure what you mean. Did you mean store the fullpath into column A of Workbooks("4-26-16 testing2.xlsm")? If so, I assume that you want it in the next blank cell of column A of Workbooks("4-26-16 testing2.xlsm"). This is unlikely to be the activecell.