Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.charting
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.charting
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.charting
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Opening file in Excel 2003 opens multipule instances of same file | Excel Discussion (Misc queries) | |||
File:1 and File:2 -- Double Files when Opening One File | Excel Discussion (Misc queries) | |||
opening an excel file opens a duplicate file of the same file | Excel Discussion (Misc queries) | |||
"Unable to read file" error message when opening a Excel file that contains a PivotTable report. | Charts and Charting in Excel | |||
How to use the exact format in a csv file when opening a csv file | Excel Discussion (Misc queries) |