Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default How to code macro with condition?

If specific file is currently opened, then not processing following coding,
else process them.
Does anyone have any suggestions on how to code it in macro?
Thanks in advance for any suggestions
Eric

Sub RunOrNot

'Is specific file opened? if not, then process following coding
Coding
'End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default How to code macro with condition?

fName = "SomeFile.xls" '<<< The file you want to check
For Each wb In Application.Workbooks
If wb.Name = fName Then
Exit Sub
Else
"Run the code
End If
Next



"Eric" wrote in message
...
If specific file is currently opened, then not processing following
coding,
else process them.
Does anyone have any suggestions on how to code it in macro?
Thanks in advance for any suggestions
Eric

Sub RunOrNot

'Is specific file opened? if not, then process following coding
Coding
'End If

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default How to code macro with condition?

Use a function as below...

Sub Macro()

If IsWorkbookOpen("Book1") = False Then
'Place your code below

End If

End Sub

Function IsWorkbookOpen(strWorkbook) As Boolean
Dim wb As Workbook
On Error Resume Next
Set wb = Workbooks(strWorkbook)
If Not wb Is Nothing Then IsWorkbookOpen = True
End Function


--
Jacob (MVP - Excel)


"Eric" wrote:

If specific file is currently opened, then not processing following coding,
else process them.
Does anyone have any suggestions on how to code it in macro?
Thanks in advance for any suggestions
Eric

Sub RunOrNot

'Is specific file opened? if not, then process following coding
Coding
'End If

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default How to code macro with condition?

It does not work, the opened file is still being opened as read only.
Does anyone have any suggestions?
Thanks in advance for any suggestions
Eric

Dim WkbkName As String
WkbkName = "D:\file1.xls"

If IsWorkbookOpen(WkbkName) = False Then
'Place your code below
End IF

"Jacob Skaria" wrote:

Use a function as below...

Sub Macro()

If IsWorkbookOpen("Book1") = False Then
'Place your code below

End If

End Sub

Function IsWorkbookOpen(strWorkbook) As Boolean
Dim wb As Workbook
On Error Resume Next
Set wb = Workbooks(strWorkbook)
If Not wb Is Nothing Then IsWorkbookOpen = True
End Function


--
Jacob (MVP - Excel)


"Eric" wrote:

If specific file is currently opened, then not processing following coding,
else process them.
Does anyone have any suggestions on how to code it in macro?
Thanks in advance for any suggestions
Eric

Sub RunOrNot

'Is specific file opened? if not, then process following coding
Coding
'End If

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,670
Default How to code macro with condition?

Is there any code to check whether the file is opened or not?
Thanks in advance for any suggestions
Eric

"JLGWhiz" wrote:

fName = "SomeFile.xls" '<<< The file you want to check
For Each wb In Application.Workbooks
If wb.Name = fName Then
Exit Sub
Else
"Run the code
End If
Next



"Eric" wrote in message
...
If specific file is currently opened, then not processing following
coding,
else process them.
Does anyone have any suggestions on how to code it in macro?
Thanks in advance for any suggestions
Eric

Sub RunOrNot

'Is specific file opened? if not, then process following coding
Coding
'End If

End Sub



.

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
Code condition LiAD Excel Programming 3 December 8th 09 10:45 AM
code to check condition for each row Horatio J. Bilge, Jr. Excel Discussion (Misc queries) 3 February 10th 09 08:07 PM
How to code macro with if condition? Eric Excel Programming 2 March 16th 08 03:54 PM
Condition Formatting in code. How? Corey Excel Programming 1 August 11th 06 03:18 PM
Condition Formatting in code. How? raypayette[_45_] Excel Programming 1 August 11th 06 02:55 PM


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