Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default If, Then, Else Coding Problem

Greetings:
Judging by problem show below, I think I better book in for another year
of pre-school.

Code shown below: always skips from line 2 to line 4.
I have my codes in a file called Menu.xls. (will become an add-in, when
completed)
In case it was "reading" that file, I copied the code into a file called
EM_1234.xls
It still won't work.

A: What am I missing in my code?
B: Do I need something to indicate that FName is a short form for FileName?
In order for VB to understand it?
C: Will the code, when stored (in its entirety) as an add-in, "know" that
it has
to work on the currently active workbook?

Sub CheckFileName()
' If File Name Starts with 'EM_', Then Process CALL Not Allowed
' If File Name does NOT start with 'EM_', Then Exit Sub

1 Dim FName As String
2 If Left(FName, 3) = "EM_" Then
3 Call NotAllowed
4 Else: Exit Sub
5 End If

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
ADG ADG is offline
external usenet poster
 
Posts: 76
Default If, Then, Else Coding Problem

You declared FName as a string, but it has no value it is empty. You need to
assign the value to it. E.g. FName = activeworkbook.Name
--
Tony Green


"BEEJAY" wrote:

Greetings:
Judging by problem show below, I think I better book in for another year
of pre-school.

Code shown below: always skips from line 2 to line 4.
I have my codes in a file called Menu.xls. (will become an add-in, when
completed)
In case it was "reading" that file, I copied the code into a file called
EM_1234.xls
It still won't work.

A: What am I missing in my code?
B: Do I need something to indicate that FName is a short form for FileName?
In order for VB to understand it?
C: Will the code, when stored (in its entirety) as an add-in, "know" that
it has
to work on the currently active workbook?

Sub CheckFileName()
' If File Name Starts with 'EM_', Then Process CALL Not Allowed
' If File Name does NOT start with 'EM_', Then Exit Sub

1 Dim FName As String
2 If Left(FName, 3) = "EM_" Then
3 Call NotAllowed
4 Else: Exit Sub
5 End If

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default If, Then, Else Coding Problem

If you want to test whether the active workbook name start with EM_
then try this:

Sub CheckFileName()
' If File Name Starts with 'EM_', Then Process CALL Not Allowed
' If File Name does NOT start with 'EM_', Then Exit Sub

1 Dim FName As String
FName = ActiveWorkbook.Name
2 If Left(FName, 3) = "EM_" Then
3 Call NotAllowed
4 Else: Exit Sub
5 End If

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default If, Then, Else Coding Problem

If you want to test whether the active workbook name start with EM_
then try this:

Sub CheckFileName()
' If File Name Starts with 'EM_', Then Process CALL Not Allowed
' If File Name does NOT start with 'EM_', Then Exit Sub

1 Dim FName As String
FName = ActiveWorkbook.Name
2 If Left(FName, 3) = "EM_" Then
3 Call NotAllowed
4 Else: Exit Sub
5 End If

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default If, Then, Else Coding Problem

Works like a dream - Thanks so much


"Karim Benabd" wrote:

If you want to test whether the active workbook name start with EM_
then try this:

Sub CheckFileName()
' If File Name Starts with 'EM_', Then Process CALL Not Allowed
' If File Name does NOT start with 'EM_', Then Exit Sub

1 Dim FName As String
FName = ActiveWorkbook.Name
2 If Left(FName, 3) = "EM_" Then
3 Call NotAllowed
4 Else: Exit Sub
5 End If


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
Help with my coding problem? Dan the Man[_2_] Excel Worksheet Functions 3 September 11th 07 12:02 AM
problem with coding Subs Excel Programming 5 September 26th 05 03:56 PM
Please help: Coding Problem Tim Excel Programming 4 June 28th 05 05:41 AM
Coding problem John[_105_] Excel Programming 3 June 22nd 05 05:39 PM
Excel Coding Problem Fraggs[_14_] Excel Programming 3 April 20th 04 01:50 PM


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