Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a semi variable name with a macro
I want to open a semi variable file name with a macro, the 1st characters are
variable the last ones are not, this is the form of the filename : "20060111 - cf_011106_110818_cgcflh.CSV" everything but cgcflh is variable but is always in the same format, can anyone help me ?? -- Don Seegers |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a semi variable name with a macro
I would let the user select the file:
option explicit sub testme() dim myFileName as variant dim newwkbk as workbook myfilename = application.getopenfilename("CSV files, *.csv") if myfilename = false then exit sub end if set curwks = activesheet set newwkbk = workbooks.open(filename:=myfilename) '...do some real work end sub Don Seegers wrote: I want to open a semi variable file name with a macro, the 1st characters are variable the last ones are not, this is the form of the filename : "20060111 - cf_011106_110818_cgcflh.CSV" everything but cgcflh is variable but is always in the same format, can anyone help me ?? -- Don Seegers -- Dave Peterson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a semi variable name with a macro
That is what i'm doing now, but users can make mistakes so i want to put in
in the macro. but thanx anyways Don Seegers wrote: I want to open a semi variable file name with a macro, the 1st characters are variable the last ones are not, this is the form of the filename : "20060111 - cf_011106_110818_cgcflh.CSV" everything but cgcflh is variable but is always in the same format, can anyone help me ?? -- Don Seegers |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a semi variable name with a macro
If there's only one file like that in the folder:
Option Explicit Sub testme01() Dim myFile As String Dim myPath As String Dim FoundIt As Boolean Dim wkbk As Workbook 'change to point at the folder to check myPath = "c:\my documents\excel" If Right(myPath, 1) < "\" Then myPath = myPath & "\" End If myFile = "" On Error Resume Next myFile = Dir(myPath & "*.csv") On Error GoTo 0 If myFile = "" Then MsgBox "no files found" Exit Sub End If FoundIt = False Do While myFile < "" If LCase(myFile) Like "*cgcflh.csv" Then FoundIt = True Exit Do End If myFile = Dir() Loop If FoundIt = True Then Set wkbk = Workbooks.Open(Filename:=myPath & myFile) End If End Sub Don Seegers wrote: That is what i'm doing now, but users can make mistakes so i want to put in in the macro. but thanx anyways Don Seegers wrote: I want to open a semi variable file name with a macro, the 1st characters are variable the last ones are not, this is the form of the filename : "20060111 - cf_011106_110818_cgcflh.CSV" everything but cgcflh is variable but is always in the same format, can anyone help me ?? -- Don Seegers -- Dave Peterson |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a semi variable name with a macro
Thanx Dave,
This did the trick Dave Peterson wrote: If there's only one file like that in the folder: Option Explicit Sub testme01() Dim myFile As String Dim myPath As String Dim FoundIt As Boolean Dim wkbk As Workbook 'change to point at the folder to check myPath = "c:\my documents\excel" If Right(myPath, 1) < "\" Then myPath = myPath & "\" End If myFile = "" On Error Resume Next myFile = Dir(myPath & "*.csv") On Error GoTo 0 If myFile = "" Then MsgBox "no files found" Exit Sub End If FoundIt = False Do While myFile < "" If LCase(myFile) Like "*cgcflh.csv" Then FoundIt = True Exit Do End If myFile = Dir() Loop If FoundIt = True Then Set wkbk = Workbooks.Open(Filename:=myPath & myFile) End If End Sub That is what i'm doing now, but users can make mistakes so i want to put in in the macro. [quoted text clipped - 11 lines] -- Don Seegers -- Don Seegers Message posted via http://www.officekb.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Running a variable macro when any value is entered into a variable cell | Excel Programming | |||
Need macro to open a variable filename | Excel Programming | |||
open file (as variable) from macro | Excel Discussion (Misc queries) | |||
Macro Creating Variable and using variable in a SQL statement | Excel Programming | |||
Forcing a macro to (semi-) automatically run | Excel Programming |