Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Dynamic File Loading

Hi,
From within an excel macro, I need to open another existing .xls
file. This file is one of many contained in a folder, which one that is
required will be dependent on a value assigned to a variable (vSpec).
The file will need to be selected because it contains the data held
within the variable - e.g.;

XXX 123.xls
XXX 234.xls
XXX 345.xls
XXY 456.xls

vSpec = 234 - Therefore XXX 234.xls needs to be opened

Can you please advise what code I need to be able to do this?

Thanks in advance.

Rob Edwards

Always look on the bright side of life!

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Dynamic File Loading

Rob,

Sub OpenTest()
Dim vSpec As String
vSpec = "234"
Workbooks.Open "XXX" & vSpec & ".xls"
End Sub

Regards,
Jim Cone
San Francisco, USA


"Rob Edwards"
wrote in message
...
Hi,
From within an excel macro, I need to open another existing .xls
file. This file is one of many contained in a folder, which one that is
required will be dependent on a value assigned to a variable (vSpec).
The file will need to be selected because it contains the data held
within the variable - e.g.;
XXX 123.xls
XXX 234.xls
XXX 345.xls
XXY 456.xls
vSpec = 234 - Therefore XXX 234.xls needs to be opened
Can you please advise what code I need to be able to do this?
Thanks in advance.
Rob Edwards
Always look on the bright side of life!
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Dynamic File Loading

Jim,
Thanks for your reply, but I guess I did not make things clear
enough - Sorry!

The XXX part could be anything & there is no way to know in advance.
This is the reason why I need to load the file based on it containing
the variable - this is the only thing I will know for sure.

Plese advise.

Rob Edwards

Always look on the bright side of life!

*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Dynamic File Loading

Rob,

Clarity is a rarity in these newsgroups - from both the poster
and the person answering. <g

Please read the directions...
'--------------------------------
Sub SurveyAndOpenFile()
'Jim Cone - San Francisco, USA - Sept. 2005
'Opens a workbook file meeting specified criteria.
'Uses the "like" operator to identify the file name.

'Requires a project reference to "Microsoft Scripting Runtime" library.
'Change "strPath" to the appropriate folder path.
'Change vSpec to the appropriate value.

Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim objFile As Scripting.File
Dim strPath As String
Dim strName As String
Dim vSpec As String

'Specify the file number
vSpec = "234"
'Specify the folder...
strPath = "C:\Documents and Settings\user\My Documents\Excel Files"
'Specify the file to look for...
strName = "*" & vSpec & ".xls"
'Use Microsoft Scripting Runtime code.
Set objFSO = New Scripting.FileSystemObject
Set objFolder = objFSO.GetFolder(strPath)

For Each objFile In objFolder.Files
If objFile.Name Like strName Then
Workbooks.Open objFile.Name
Exit For
End If
Next 'objFile

Set objFile = Nothing
Set objFSO = Nothing
Set objFolder = Nothing
End Sub
'-----------------------------


"Rob Edwards" wrote in message ...
Jim,
Thanks for your reply, but I guess I did not make things clear
enough - Sorry!
The XXX part could be anything & there is no way to know in advance.
This is the reason why I need to load the file based on it containing
the variable - this is the only thing I will know for sure.
Plese advise.
Rob Edwards
Always look on the bright side of life!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Dynamic File Loading

Thanks!

Rob Edwards

Always look on the bright side of life!

*** Sent via Developersdex http://www.developersdex.com ***


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
loading ocx file. funkymonkUK[_18_] Excel Programming 3 June 6th 05 01:15 PM
loading a ocx file VBAfunkymonk Excel Programming 1 June 6th 05 01:06 PM
File Loading Problems Jason Hancock Excel Programming 1 June 30th 04 03:14 AM
Loading an Excel file Kevin Sprinkel Excel Programming 0 February 6th 04 04:46 PM
Loading text file Clayton L. Wilson Excel Programming 3 July 22nd 03 03:28 PM


All times are GMT +1. The time now is 01:44 PM.

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"