#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Open File

Hi, I am new to VB and cant find how to get my macro to open a file. I know
the location of the file but not the filename, I need the user to pick which
file to open. Basically I need the VB to display Excels Open Dialog Box

Many thanks in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Open File

Sub test()
Dim F As Variant
Dim Myfolder As String
Myfolder = "C:\Temp"
ChDrive Myfolder
ChDir Myfolder

F = Application.GetOpenFilename("XL Files (*.xl*), *.XL*")
If F = False Then Exit Sub
Workbooks.Open F
End Sub

HTH. Best wishes Harald

"PraxisPete" skrev i melding
...
Hi, I am new to VB and can't find how to get my macro to open a file. I

know
the location of the file but not the filename, I need the user to pick

which
file to open. Basically I need the VB to display Excel's Open Dialog Box

Many thanks in advance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Open File

Thanks for that Harald, a further development of that is, if all the files
that could be opened required the same password and were to be open as read
only, can this be coded in?

Thank you again

"Harald Staff" wrote:

Sub test()
Dim F As Variant
Dim Myfolder As String
Myfolder = "C:\Temp"
ChDrive Myfolder
ChDir Myfolder

F = Application.GetOpenFilename("XL Files (*.xl*), *.XL*")
If F = False Then Exit Sub
Workbooks.Open F
End Sub

HTH. Best wishes Harald

"PraxisPete" skrev i melding
...
Hi, I am new to VB and can't find how to get my macro to open a file. I

know
the location of the file but not the filename, I need the user to pick

which
file to open. Basically I need the VB to display Excel's Open Dialog Box

Many thanks in advance




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Open File

Pete,
Read up on the optional parameters to .Open in the help.

NickHK

"PraxisPete" wrote in message
...
Thanks for that Harald, a further development of that is, if all the files
that could be opened required the same password and were to be open as

read
only, can this be coded in?

Thank you again

"Harald Staff" wrote:

Sub test()
Dim F As Variant
Dim Myfolder As String
Myfolder = "C:\Temp"
ChDrive Myfolder
ChDir Myfolder

F = Application.GetOpenFilename("XL Files (*.xl*), *.XL*")
If F = False Then Exit Sub
Workbooks.Open F
End Sub

HTH. Best wishes Harald

"PraxisPete" skrev i melding
...
Hi, I am new to VB and can't find how to get my macro to open a file.

I
know
the location of the file but not the filename, I need the user to pick

which
file to open. Basically I need the VB to display Excel's Open Dialog

Box

Many thanks in advance






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Open File

Thanks NickHK,
I've read that and can see that there are parameters for ReadOnly and
Password, but, as I understand it, the Open Method requires the FileName
which I do not have, the GetOpenFilename does not need the Filename, but does
not have parameters for ReadOnly and Password. Its like I need a combination
of both.
Many thanks.

"NickHK" wrote:

Pete,
Read up on the optional parameters to .Open in the help.

NickHK

"PraxisPete" wrote in message
...
Thanks for that Harald, a further development of that is, if all the files
that could be opened required the same password and were to be open as

read
only, can this be coded in?

Thank you again

"Harald Staff" wrote:

Sub test()
Dim F As Variant
Dim Myfolder As String
Myfolder = "C:\Temp"
ChDrive Myfolder
ChDir Myfolder

F = Application.GetOpenFilename("XL Files (*.xl*), *.XL*")
If F = False Then Exit Sub
Workbooks.Open F
End Sub

HTH. Best wishes Harald

"PraxisPete" skrev i melding
...
Hi, I am new to VB and can't find how to get my macro to open a file.

I
know
the location of the file but not the filename, I need the user to pick
which
file to open. Basically I need the VB to display Excel's Open Dialog

Box

Many thanks in advance









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default Open File

No, very wrong.
GetOpenFilename does just what it says, gets the filename for a file to be
opened. It doesn NOT open the file. The filename is F in my code.

This F is passed to the Open method in the last line, which is where you add
the parameters:

Workbooks.Open F, , True, , "Password"

HTH. best wishes Harald

"PraxisPete" skrev i melding
...
Thanks NickHK,
I've read that and can see that there are parameters for ReadOnly and
Password, but, as I understand it, the Open Method requires the FileName
which I do not have, the GetOpenFilename does not need the Filename, but
does
not have parameters for ReadOnly and Password. Its like I need a
combination
of both.
Many thanks.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Open File

Thank you all for your help. You will have to forgive me for being a bit
slow on the uptake, I am starter at this, but I do understand now.

"Harald Staff" wrote:

No, very wrong.
GetOpenFilename does just what it says, gets the filename for a file to be
opened. It doesn NOT open the file. The filename is F in my code.

This F is passed to the Open method in the last line, which is where you add
the parameters:

Workbooks.Open F, , True, , "Password"

HTH. best wishes Harald

"PraxisPete" skrev i melding
...
Thanks NickHK,
I've read that and can see that there are parameters for ReadOnly and
Password, but, as I understand it, the Open Method requires the FileName
which I do not have, the GetOpenFilename does not need the Filename, but
does
not have parameters for ReadOnly and Password. Its like I need a
combination
of both.
Many thanks.




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default Open File

No problem. Glad to assist.

Best wishes Harald.

"PraxisPete" skrev i melding
...
Thank you all for your help. You will have to forgive me for being a bit
slow on the uptake, I am starter at this, but I do understand now.



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
Unable to open a 82 KB XLSM file due to "Too many different cellformats" & "Converter failed to open the file." errors. Phillip Pi Excel Discussion (Misc queries) 0 April 23rd 09 08:53 PM
Unable to open a 82 KB XLSM file due to "Too many different cellformats" & "Converter failed to open the file." errors. Phillip Pi Setting up and Configuration of Excel 0 April 23rd 09 08:53 PM
excel 2003 saved file will not open without a blank workbook open Bob Excel Discussion (Misc queries) 4 November 11th 06 04:24 PM
In Excel - Use Windows Explorer instead of File Open to open file KymY Excel Discussion (Misc queries) 1 August 5th 06 09:59 PM
How do I stop Excel from closing the open file each time I open a. Welsin Setting up and Configuration of Excel 3 January 8th 05 11:16 PM


All times are GMT +1. The time now is 11:57 PM.

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

About Us

"It's about Microsoft Excel"