#1   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 201
Default Opening a file

Hi guys, I'm becoming increasingly frustrated with what I think is a
relatively simple procedure.

I am creating a process that requires the user to open a file (I'm not sure
where it will be saved), and then the code will simply copy some data out of
this selected file into the template document.

I currently have:

Public Sub ImportData()

Dim curfolder As String
Dim filename As String

Sheets("Sheet1").Select
Range("A1:ED1000").Select
Selection.ClearContents

Application.GetOpenFilename
filename = Dir(curfolder)

Workbooks.Open filename
Range("A1:ED1000").Select
Selection.Copy



However, when I reach the select file dialog box and select the necessary
file, the file I want isn't actually selected, but the first file in that
folder.

Can someone help me with this predicament please?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 2,489
Default Opening a file

Hi,

You are mixing up two methods of getting filenames.
The GetOpenfilename displays the folder view and returns the selected
filename, or False is none is picked.
The DIR command returns filenames that match a given search string, eg:
"C:\myfolder\*.xls"


Dim Filename As Variant

Filename = Application.GetOpenFilename
If Filename = False Then
MsgBox "No file selected"
Else
MsgBox "Process file " & Filename
End If

Cheers
Andy

--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
"Phil" wrote in message
...
Hi guys, I'm becoming increasingly frustrated with what I think is a
relatively simple procedure.

I am creating a process that requires the user to open a file (I'm not
sure
where it will be saved), and then the code will simply copy some data out
of
this selected file into the template document.

I currently have:

Public Sub ImportData()

Dim curfolder As String
Dim filename As String

Sheets("Sheet1").Select
Range("A1:ED1000").Select
Selection.ClearContents

Application.GetOpenFilename
filename = Dir(curfolder)

Workbooks.Open filename
Range("A1:ED1000").Select
Selection.Copy



However, when I reach the select file dialog box and select the necessary
file, the file I want isn't actually selected, but the first file in that
folder.

Can someone help me with this predicament please?

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 201
Default Opening a file

Cheers Andy, that works a treat.

"Andy Pope" wrote:

Hi,

You are mixing up two methods of getting filenames.
The GetOpenfilename displays the folder view and returns the selected
filename, or False is none is picked.
The DIR command returns filenames that match a given search string, eg:
"C:\myfolder\*.xls"


Dim Filename As Variant

Filename = Application.GetOpenFilename
If Filename = False Then
MsgBox "No file selected"
Else
MsgBox "Process file " & Filename
End If

Cheers
Andy

--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
"Phil" wrote in message
...
Hi guys, I'm becoming increasingly frustrated with what I think is a
relatively simple procedure.

I am creating a process that requires the user to open a file (I'm not
sure
where it will be saved), and then the code will simply copy some data out
of
this selected file into the template document.

I currently have:

Public Sub ImportData()

Dim curfolder As String
Dim filename As String

Sheets("Sheet1").Select
Range("A1:ED1000").Select
Selection.ClearContents

Application.GetOpenFilename
filename = Dir(curfolder)

Workbooks.Open filename
Range("A1:ED1000").Select
Selection.Copy



However, when I reach the select file dialog box and select the necessary
file, the file I want isn't actually selected, but the first file in that
folder.

Can someone help me with this predicament please?

Thanks


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 in Excel 2003 opens multipule instances of same file Ed_B Excel Discussion (Misc queries) 1 June 21st 07 07:10 PM
File:1 and File:2 -- Double Files when Opening One File dallin Excel Discussion (Misc queries) 1 January 25th 07 02:53 AM
opening an excel file opens a duplicate file of the same file skm Excel Discussion (Misc queries) 1 December 7th 05 05:52 PM
"Unable to read file" error message when opening a Excel file that contains a PivotTable report. Tim Marsden Charts and Charting in Excel 2 October 15th 05 02:10 PM
How to use the exact format in a csv file when opening a csv file tong Excel Discussion (Misc queries) 1 October 13th 05 05:41 AM


All times are GMT +1. The time now is 10:20 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"