Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 226
Default Create Move Macro for Closed Workbook

Hello,

I have a Worksheet in a Book that Im moving to another Workbook (WKB2).
Im looking to create a Macro which looks to see if WKB2 is closed. If
its closed, I would like to insert the sheet from the first Workbook
(WKB1).

Since I only want to have it perform the action if the other workbook is
closed, is there also a way to create a message to alert the user in the
event the workbook is open - - - meaning don't move it in that case?

Thanks for your review Roger
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default Create Move Macro for Closed Workbook

This is a function a friend helped me to create when I had a similar issue:
you will need to insert "Part 1" in your macro and use "Part 2" to create a
"public function" (similar to a new macro) in your module.

"Part 1" - put the following in your macro:

If WorkbookIsOpen("WORKBOOK NAME") < True Then
'Insert your code here to move the sheet
Else
'Insert a warning message or something to tell you the workbook was open.
End If

"Part 2" - just copy and past this code in your module after your macro
(after the "End Sub"

Public Function WorkbookIsOpen(wbname) As Boolean

' Returns TRUE if the workbook is open

Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbname)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If

End Function

What this will do is give "TRUE" if the workbook you name (in the IF
statement above) is open. Of course you can use the "IF...ELSE...END IF" to
give you a warning message should the workbook be open.

"Roger" wrote:

Hello,

I have a Worksheet in a Book that Im moving to another Workbook (WKB2).
Im looking to create a Macro which looks to see if WKB2 is closed. If
its closed, I would like to insert the sheet from the first Workbook
(WKB1).

Since I only want to have it perform the action if the other workbook is
closed, is there also a way to create a message to alert the user in the
event the workbook is open - - - meaning don't move it in that case?

Thanks for your review Roger

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default Create Move Macro for Closed Workbook

Just so there is no confusion, your IF... Then statement should look as
follows:

If WorkbookIsOpen("WKB2") < True Then
'Insert your code here to move the sheet
Else
'Insert a warning message or something to tell you the workbook was open.
End If

Hope this helps.


"Jeff" wrote:

This is a function a friend helped me to create when I had a similar issue:
you will need to insert "Part 1" in your macro and use "Part 2" to create a
"public function" (similar to a new macro) in your module.

"Part 1" - put the following in your macro:

If WorkbookIsOpen("WORKBOOK NAME") < True Then
'Insert your code here to move the sheet
Else
'Insert a warning message or something to tell you the workbook was open.
End If

"Part 2" - just copy and past this code in your module after your macro
(after the "End Sub"

Public Function WorkbookIsOpen(wbname) As Boolean

' Returns TRUE if the workbook is open

Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbname)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If

End Function

What this will do is give "TRUE" if the workbook you name (in the IF
statement above) is open. Of course you can use the "IF...ELSE...END IF" to
give you a warning message should the workbook be open.

"Roger" wrote:

Hello,

I have a Worksheet in a Book that Im moving to another Workbook (WKB2).
Im looking to create a Macro which looks to see if WKB2 is closed. If
its closed, I would like to insert the sheet from the first Workbook
(WKB1).

Since I only want to have it perform the action if the other workbook is
closed, is there also a way to create a message to alert the user in the
event the workbook is open - - - meaning don't move it in that case?

Thanks for your review Roger

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 226
Default Create Move Macro for Closed Workbook

Thank you Jeff. This helps out immensely and gives me a good direction to
start from.

Appreciate you help - Roger




"Jeff" wrote:

Just so there is no confusion, your IF... Then statement should look as
follows:

If WorkbookIsOpen("WKB2") < True Then
'Insert your code here to move the sheet
Else
'Insert a warning message or something to tell you the workbook was open.
End If

Hope this helps.


"Jeff" wrote:

This is a function a friend helped me to create when I had a similar issue:
you will need to insert "Part 1" in your macro and use "Part 2" to create a
"public function" (similar to a new macro) in your module.

"Part 1" - put the following in your macro:

If WorkbookIsOpen("WORKBOOK NAME") < True Then
'Insert your code here to move the sheet
Else
'Insert a warning message or something to tell you the workbook was open.
End If

"Part 2" - just copy and past this code in your module after your macro
(after the "End Sub"

Public Function WorkbookIsOpen(wbname) As Boolean

' Returns TRUE if the workbook is open

Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbname)
If Err = 0 Then
WorkbookIsOpen = True
Else
WorkbookIsOpen = False
End If

End Function

What this will do is give "TRUE" if the workbook you name (in the IF
statement above) is open. Of course you can use the "IF...ELSE...END IF" to
give you a warning message should the workbook be open.

"Roger" wrote:

Hello,

I have a Worksheet in a Book that Im moving to another Workbook (WKB2).
Im looking to create a Macro which looks to see if WKB2 is closed. If
its closed, I would like to insert the sheet from the first Workbook
(WKB1).

Since I only want to have it perform the action if the other workbook is
closed, is there also a way to create a message to alert the user in the
event the workbook is open - - - meaning don't move it in that case?

Thanks for your review Roger

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
create personal macro workbook krispylala Excel Worksheet Functions 3 December 6th 07 04:38 PM
Macro to create new workbook and sheets Richard Excel Discussion (Misc queries) 1 July 31st 07 07:31 PM
Using a macro to create a macro in another workbook Gizmo63 Excel Worksheet Functions 2 May 15th 06 09:48 AM
What function would move a closed record to another worksheet? Stephen Excel Worksheet Functions 1 April 27th 06 06:27 AM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM


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