Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Opening file by partial name in same folder as master file

Please Help!!

I have a master file called "All Reports.xls" that opens up various Reports
files(Ex: ABC_G016_GPUS.xls, BCD_G027_GPUS.xls, JKL_G034_GPUS.xls). The
Report files are in the same network folder as the master file and are
updated frequently. The Report files also have names that constantly change
when they are updated. The only part of the filename that does not change
begins with "G" followed by 3 numbers. By reading previous posts, I was able
to figure out how to open the "G016" Report file with the code below.

Workbooks.Open ActiveWorkbook.Path & "ABC_G016_GPUS.xls"

How do I open the file by only the "G016" part of the filename? I tried the
code below, but it did not work:

Workbooks.Open ActiveWorkbook.Path & "*" & G016 & "*.xls"

I appreciate your help!!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Opening file by partial name in same folder as master file

maybe something like this:

Sub test()
Dim FileToOpen As String

FileToOpen = Dir(ActiveWorkbook.Path & "*" & "G016" & "*.xls")
If FileToOpen < "" Then
Workbooks.Open FileToOpen
End If

End Sub


--


Gary Keramidas
Excel 2003


"shiloh13" <u59050@uwe wrote in message news:a5b747aa8da6d@uwe...
Please Help!!

I have a master file called "All Reports.xls" that opens up various
Reports
files(Ex: ABC_G016_GPUS.xls, BCD_G027_GPUS.xls, JKL_G034_GPUS.xls). The
Report files are in the same network folder as the master file and are
updated frequently. The Report files also have names that constantly
change
when they are updated. The only part of the filename that does not change
begins with "G" followed by 3 numbers. By reading previous posts, I was
able
to figure out how to open the "G016" Report file with the code below.

Workbooks.Open ActiveWorkbook.Path & "ABC_G016_GPUS.xls"

How do I open the file by only the "G016" part of the filename? I tried
the
code below, but it did not work:

Workbooks.Open ActiveWorkbook.Path & "*" & G016 & "*.xls"

I appreciate your help!!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Opening file by partial name in same folder as master file

Workbooks.Open FileToOpen

The above line from your code should be this...

Workbooks.Open ActiveWorkbook.Path & FileToOpen

Since the Dir function returns only the file's name (without the path
associated with it).

--
Rick (MVP - Excel)



"Gary Keramidas" wrote in message
...
maybe something like this:

Sub test()
Dim FileToOpen As String

FileToOpen = Dir(ActiveWorkbook.Path & "*" & "G016" & "*.xls")
If FileToOpen < "" Then
Workbooks.Open FileToOpen
End If

End Sub


--


Gary Keramidas
Excel 2003


"shiloh13" <u59050@uwe wrote in message news:a5b747aa8da6d@uwe...
Please Help!!

I have a master file called "All Reports.xls" that opens up various
Reports
files(Ex: ABC_G016_GPUS.xls, BCD_G027_GPUS.xls, JKL_G034_GPUS.xls). The
Report files are in the same network folder as the master file and are
updated frequently. The Report files also have names that constantly
change
when they are updated. The only part of the filename that does not
change
begins with "G" followed by 3 numbers. By reading previous posts, I was
able
to figure out how to open the "G016" Report file with the code below.

Workbooks.Open ActiveWorkbook.Path & "ABC_G016_GPUS.xls"

How do I open the file by only the "G016" part of the filename? I tried
the
code below, but it did not work:

Workbooks.Open ActiveWorkbook.Path & "*" & G016 & "*.xls"

I appreciate your help!!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Opening file by partial name in same folder as master file

thanks

--


Gary Keramidas
Excel 2003


"Rick Rothstein" wrote in message
...
Workbooks.Open FileToOpen


The above line from your code should be this...

Workbooks.Open ActiveWorkbook.Path & FileToOpen

Since the Dir function returns only the file's name (without the path
associated with it).

--
Rick (MVP - Excel)



"Gary Keramidas" wrote in message
...
maybe something like this:

Sub test()
Dim FileToOpen As String

FileToOpen = Dir(ActiveWorkbook.Path & "*" & "G016" & "*.xls")
If FileToOpen < "" Then
Workbooks.Open FileToOpen
End If

End Sub


--


Gary Keramidas
Excel 2003


"shiloh13" <u59050@uwe wrote in message news:a5b747aa8da6d@uwe...
Please Help!!

I have a master file called "All Reports.xls" that opens up various
Reports
files(Ex: ABC_G016_GPUS.xls, BCD_G027_GPUS.xls, JKL_G034_GPUS.xls). The
Report files are in the same network folder as the master file and are
updated frequently. The Report files also have names that constantly
change
when they are updated. The only part of the filename that does not
change
begins with "G" followed by 3 numbers. By reading previous posts, I was
able
to figure out how to open the "G016" Report file with the code below.

Workbooks.Open ActiveWorkbook.Path & "ABC_G016_GPUS.xls"

How do I open the file by only the "G016" part of the filename? I tried
the
code below, but it did not work:

Workbooks.Open ActiveWorkbook.Path & "*" & G016 & "*.xls"

I appreciate your help!!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Opening file by partial name in same folder as master file


I think that the backslash should also be included in both lines. Seems to
be OK without if the current default directory is also the activeworkbook
directory but can one be sure of that.

Sub test()

Dim FileToOpen As String

FileToOpen = Dir(ActiveWorkbook.Path & "\" & "*" & "G016" & "*.xls")

If FileToOpen < "" Then
Workbooks.Open ActiveWorkbook.Path & "\" & FileToOpen
End If

End Sub

--
Regards,

OssieMac


"Rick Rothstein" wrote:

Workbooks.Open FileToOpen


The above line from your code should be this...

Workbooks.Open ActiveWorkbook.Path & FileToOpen

Since the Dir function returns only the file's name (without the path
associated with it).

--
Rick (MVP - Excel)



"Gary Keramidas" wrote in message
...
maybe something like this:

Sub test()
Dim FileToOpen As String

FileToOpen = Dir(ActiveWorkbook.Path & "*" & "G016" & "*.xls")
If FileToOpen < "" Then
Workbooks.Open FileToOpen
End If

End Sub


--


Gary Keramidas
Excel 2003


"shiloh13" <u59050@uwe wrote in message news:a5b747aa8da6d@uwe...
Please Help!!

I have a master file called "All Reports.xls" that opens up various
Reports
files(Ex: ABC_G016_GPUS.xls, BCD_G027_GPUS.xls, JKL_G034_GPUS.xls). The
Report files are in the same network folder as the master file and are
updated frequently. The Report files also have names that constantly
change
when they are updated. The only part of the filename that does not
change
begins with "G" followed by 3 numbers. By reading previous posts, I was
able
to figure out how to open the "G016" Report file with the code below.

Workbooks.Open ActiveWorkbook.Path & "ABC_G016_GPUS.xls"

How do I open the file by only the "G016" part of the filename? I tried
the
code below, but it did not work:

Workbooks.Open ActiveWorkbook.Path & "*" & G016 & "*.xls"

I appreciate your help!!


.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Opening file by partial name in same folder as master file

I don't think you can just add the backslash like that because if it is not
needed then I think it will screw up the path (you would have two
backslashes next to each other with nothing between them). To handle the
situation you are describing would need code something like this I think
(using your code snippet as a base)...

Sub test()
Dim FileToOpen As String, Path As String

Path = ActiveWorkbook.Path
If Right(Path, 1) < "\" Then Path = Path & "\"
FileToOpen = Dir(Path & "*" & "G016" & "*.xls")

If FileToOpen < "" Then
Workbooks.Open Path & FileToOpen
End If
End Sub

--
Rick (MVP - Excel)



"OssieMac" wrote in message
...

I think that the backslash should also be included in both lines. Seems to
be OK without if the current default directory is also the activeworkbook
directory but can one be sure of that.

Sub test()

Dim FileToOpen As String

FileToOpen = Dir(ActiveWorkbook.Path & "\" & "*" & "G016" & "*.xls")

If FileToOpen < "" Then
Workbooks.Open ActiveWorkbook.Path & "\" & FileToOpen
End If

End Sub

--
Regards,

OssieMac


"Rick Rothstein" wrote:

Workbooks.Open FileToOpen


The above line from your code should be this...

Workbooks.Open ActiveWorkbook.Path & FileToOpen

Since the Dir function returns only the file's name (without the path
associated with it).

--
Rick (MVP - Excel)



"Gary Keramidas" wrote in message
...
maybe something like this:

Sub test()
Dim FileToOpen As String

FileToOpen = Dir(ActiveWorkbook.Path & "*" & "G016" & "*.xls")
If FileToOpen < "" Then
Workbooks.Open FileToOpen
End If

End Sub


--


Gary Keramidas
Excel 2003


"shiloh13" <u59050@uwe wrote in message news:a5b747aa8da6d@uwe...
Please Help!!

I have a master file called "All Reports.xls" that opens up various
Reports
files(Ex: ABC_G016_GPUS.xls, BCD_G027_GPUS.xls, JKL_G034_GPUS.xls).
The
Report files are in the same network folder as the master file and are
updated frequently. The Report files also have names that constantly
change
when they are updated. The only part of the filename that does not
change
begins with "G" followed by 3 numbers. By reading previous posts, I
was
able
to figure out how to open the "G016" Report file with the code below.

Workbooks.Open ActiveWorkbook.Path & "ABC_G016_GPUS.xls"

How do I open the file by only the "G016" part of the filename? I
tried
the
code below, but it did not work:

Workbooks.Open ActiveWorkbook.Path & "*" & G016 & "*.xls"

I appreciate your help!!


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
opening file from ftp folder PBISMaryland Excel Discussion (Misc queries) 1 September 16th 09 11:37 AM
Open and copy all workbook sheets in a folder to a master file [email protected] Excel Discussion (Misc queries) 0 November 2nd 06 04:29 PM
Opening and deleting File with only partial Filename sean_f Excel Programming 0 April 20th 06 04:47 PM
Opening and deleting File with only partial Filename sean_f Excel Programming 0 April 20th 06 04:47 PM
opening each file in a folder JT Excel Programming 3 August 1st 05 06:35 PM


All times are GMT +1. The time now is 12:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"