Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
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
Running a variable macro when any value is entered into a variable cell [email protected] Excel Programming 3 December 14th 05 05:15 PM
Need macro to open a variable filename Steve@ABS Excel Programming 5 June 2nd 05 09:08 PM
open file (as variable) from macro d chaps Excel Discussion (Misc queries) 1 March 14th 05 11:57 PM
Macro Creating Variable and using variable in a SQL statement Jimmy Excel Programming 4 October 25th 04 02:36 AM
Forcing a macro to (semi-) automatically run Richard Owlett Excel Programming 2 February 21st 04 06:10 PM


All times are GMT +1. The time now is 01:42 AM.

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"