LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Before macro runs - check workbook name

LCase by the way as in Lower Case.

Charles
xl Geek
Jan wrote:
HTH,

Thank you. That was the problem... active.workname and iCase. It appears
to be working as needed.

Jan

"Die_Another_Day" wrote:

I'm just guessing but the macro being ran isn't in CSRreport.xls is it?
if not then use ActiveWorkbook. otherwise it could be a case sensitive
thing.
If Not lCase(ActiveWorkbook.Name) = lCase(REQUIREDFILENAME) Then

lCase forces all letters to lower case bypassing case sensitivity.
ActiveWorkbook looks at the book that is active while Thisworkbook
looks at the book with the code.

HTH

Die_Another_Day
Jan wrote:
Hi Nick,

As I mentioned previously, I know VBA very little. I choose to use the
first part of your suggestion and not the more helpful one. However, even
when the file is saved as CSRReport.xls before running the code. I receive
the message box to save the file. Below is the code that I adapted per your
suggestion. What am I doing wrong. TIA.

Sub CSRReport()
' CSRreport Macro
' Macro recorded 5/10/2006 by Administrator
'
Const REQUIREDFILENAME As String = "CSRReport.xls"

If Not ThisWorkbook.Name = REQUIREDFILENAME Then
MsgBox "Please save this workbook as " & REQUIREDFILENAME
Exit Sub
Else
If Worksheets("PastDue").Visible = True Then
Worksheets("PastDue").Visible = False
End If

Worksheets("Label Number").Select
Range("U3").Select
CSRFilter
CSRPrintarea
Range("A:A,D:D,F:G,J:M,S:S,T:T,U:U,V:V,W:W,X:X,Y:Y ,Z:Z,AA:AA").Select
Range("AA2").Activate
Selection.EntireColumn.Hidden = True
CSRTitle
End If
End Sub

"NickHK" wrote:

Nearly, but you need add a little mo
Const REQUIREDFILENAME as string="CSRReport.xls"
If Not ThisWorkbook.Name = REQUIREDFILENAME Then
MsgBox "Please save this workbook as " & REQUIREDFILENAME
Exit Sub
Else
'your code goes here
End If

But you help out the user a bit mo
Const REQUIREDFILENAME as string="CSRReport.xls"
Dim Msg as String
If Not ThisWorkbook.Name = REQUIREDFILENAME Then
Msg="This workbook must be saved as " & REQUIREDFILENAME & " before
running the routine." & vbNewLine
Msg=Msg & "Do you want save it now and continue with the routine ?"
If MsgBox (Msg,vbExclamation+vbYesNo)=vbYes
'Add the path if necessary, or Thisworkbook.Path
Thisworkbook.SaveAs REQUIREDFILENAME
Else
Exit Sub
End If
Else
'your code goes here
End If

NickHK

"terryvanduzee"
wrote in message
news:terryvanduzee.2bw398_1154483119.8324@excelfor um-nospam.com...

One way may be: Im only a newby and someone else may have a better
solution.

Add this code before the rest of your code.

If Not ThisWorkbook.Name = "CSRReport" & ".xls" Then
MsgBox "Please save this workbook as CSRReport.xls"
Else
'your code goes here
End If

Terry


--
terryvanduzee
------------------------------------------------------------------------
terryvanduzee's Profile:
http://www.excelforum.com/member.php...o&userid=37004
View this thread: http://www.excelforum.com/showthread...hreadid=567286







 
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
VBA macro runs fine, but freezes if I try to do ANYTHING else whileit runs Rruffpaw Setting up and Configuration of Excel 1 September 17th 11 01:25 PM
how to create a macro that runs other macro in the same workbook VB Script for Excel Excel Programming 4 March 23rd 06 03:53 AM
Macro runs in source , but not when in Personal Macro Workbook Darin Kramer Excel Programming 1 September 13th 05 04:48 PM
Excel Workbook automatically (by design) runs a macro Paul Excel Programming 0 August 5th 04 10:49 PM
Excel Workbook automatically (by design) runs a macro Chip Pearson Excel Programming 0 August 5th 04 08:24 PM


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