Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Is there an object property that will return the file type?

I'm writing a formatting macro that I only want to run on .txt or .csv files.
This mostly a safety feature for other users so if they accidentally press
the wrong combo of hot keys they don't have a macro run that will ruin the
spreadsheet they are currently working on.

Is there an object property I can write into the code that will return the
file type of the active workbook?

ActiveWorkbook.FileType doesn't work.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default Is there an object property that will return the file type?

Did you try .fileformat?

Cliff Edwards

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Is there an object property that will return the file type?

BookName = ThisWorkbook.Name
Booktype = Mid(BookName, InStr(BookName, ".") + 1)


"cla99009" wrote:

I'm writing a formatting macro that I only want to run on .txt or .csv files.
This mostly a safety feature for other users so if they accidentally press
the wrong combo of hot keys they don't have a macro run that will ruin the
spreadsheet they are currently working on.

Is there an object property I can write into the code that will return the
file type of the active workbook?

ActiveWorkbook.FileType doesn't work.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Is there an object property that will return the file type?

Since:

=CELL("filename",A1) in a worksheet cell will return the full path/filename,
lets use a helper cell (say Z100) to get us that extension:

Sub whatAmI()
dq = Chr(34)
s = "=CELL(" & dq & "filename" & dq & ",A1)"
ActiveSheet.Range("Z100").Formula = s
v = Right(Range("Z100").Value, 3)
MsgBox (v)
End Sub

--
Gary''s Student - gsnu200798


"cla99009" wrote:

I'm writing a formatting macro that I only want to run on .txt or .csv files.
This mostly a safety feature for other users so if they accidentally press
the wrong combo of hot keys they don't have a macro run that will ruin the
spreadsheet they are currently working on.

Is there an object property I can write into the code that will return the
file type of the active workbook?

ActiveWorkbook.FileType doesn't work.

  #5   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Is there an object property that will return the file type?

On the off chance someone uses a period in the filename (eg
File.Name.Extension), the OP might also consider using InStrRev

BookName = ThisWorkbook.Name
Booktype = Mid(BookName, InStrRev(BookName, ".") + 1)


"Joel" wrote:

BookName = ThisWorkbook.Name
Booktype = Mid(BookName, InStr(BookName, ".") + 1)


"cla99009" wrote:

I'm writing a formatting macro that I only want to run on .txt or .csv files.
This mostly a safety feature for other users so if they accidentally press
the wrong combo of hot keys they don't have a macro run that will ruin the
spreadsheet they are currently working on.

Is there an object property I can write into the code that will return the
file type of the active workbook?

ActiveWorkbook.FileType doesn't work.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Is there an object property that will return the file type?

Thanks for the pointers.

The mid function doesn't work because if a new workbook hasn't been saved
yet, it doesn't have a file type extension, which would cause an error in the
macro. I ended up using If Right(ActiveWorkbook.Name, 3) < "csv" Then Exit
Sub

It works just fine now, no errors, no messes.

"JMB" wrote:

On the off chance someone uses a period in the filename (eg
File.Name.Extension), the OP might also consider using InStrRev

BookName = ThisWorkbook.Name
Booktype = Mid(BookName, InStrRev(BookName, ".") + 1)


"Joel" wrote:

BookName = ThisWorkbook.Name
Booktype = Mid(BookName, InStr(BookName, ".") + 1)


"cla99009" wrote:

I'm writing a formatting macro that I only want to run on .txt or .csv files.
This mostly a safety feature for other users so if they accidentally press
the wrong combo of hot keys they don't have a macro run that will ruin the
spreadsheet they are currently working on.

Is there an object property I can write into the code that will return the
file type of the active workbook?

ActiveWorkbook.FileType doesn't work.

  #7   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Is there an object property that will return the file type?

glad you got it working. although if there is no period in the filename, mid
will return the entire string and not error out due to the fact that Instr
and Instrrev return 0 when they don't find the period.



"cla99009" wrote:

Thanks for the pointers.

The mid function doesn't work because if a new workbook hasn't been saved
yet, it doesn't have a file type extension, which would cause an error in the
macro. I ended up using If Right(ActiveWorkbook.Name, 3) < "csv" Then Exit
Sub

It works just fine now, no errors, no messes.

"JMB" wrote:

On the off chance someone uses a period in the filename (eg
File.Name.Extension), the OP might also consider using InStrRev

BookName = ThisWorkbook.Name
Booktype = Mid(BookName, InStrRev(BookName, ".") + 1)


"Joel" wrote:

BookName = ThisWorkbook.Name
Booktype = Mid(BookName, InStr(BookName, ".") + 1)


"cla99009" wrote:

I'm writing a formatting macro that I only want to run on .txt or .csv files.
This mostly a safety feature for other users so if they accidentally press
the wrong combo of hot keys they don't have a macro run that will ruin the
spreadsheet they are currently working on.

Is there an object property I can write into the code that will return the
file type of the active workbook?

ActiveWorkbook.FileType doesn't work.

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
Get the Data Type of a Property DrRocket Excel Programming 0 September 12th 07 06:12 PM
problem:Structure with Object reference (TYPE...END TYPE) syswizard Excel Programming 6 February 16th 07 10:00 PM
Objects with .type property atpgroups Excel Programming 0 August 2nd 06 12:00 PM
Return value of Property Get when using enumerated type jason Excel Programming 3 August 23rd 04 01:13 PM
How to find what object type is returned from Selection property ? Krzysztof Klimczak[_3_] Excel Programming 1 October 2nd 03 11:33 PM


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