Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
dkipping
 
Posts: n/a
Default Check if workbook open


Some macros I use require another workbook to open so I include a line
like Workbooks.Open Filename:= C:\My\ Documents\Orders\POTemp.xls
The problem occurs when that workbook is already open – the macro
stalls. Is there a way to bypass that instruction if the other
workbook is already open?


--
dkipping
------------------------------------------------------------------------
dkipping's Profile: http://www.excelforum.com/member.php...o&userid=34683
View this thread: http://www.excelforum.com/showthread...hreadid=544484

  #2   Report Post  
Posted to microsoft.public.excel.misc
Don Guillett
 
Posts: n/a
Default Check if workbook open

Here is one I use from a printed name in a cell. Modify to suit

Sub GetWorkbook()
If ActiveCell.Value = "" Then Exit Sub
workbookname = ActiveCell.Value
On Error GoTo OpenWorkbook
Windows(workbookname & ".xls").Activate
Exit Sub
OpenWorkbook:
Workbooks.Open(workbookname & ".xls").RunAutoMacros xlAutoOpen
End Sub

--
Don Guillett
SalesAid Software

"dkipping" wrote in
message ...

Some macros I use require another workbook to open so I include a line
like Workbooks.Open Filename:= C:\My\ Documents\Orders\POTemp.xls
The problem occurs when that workbook is already open – the macro
stalls. Is there a way to bypass that instruction if the other
workbook is already open?


--
dkipping
------------------------------------------------------------------------
dkipping's Profile:
http://www.excelforum.com/member.php...o&userid=34683
View this thread: http://www.excelforum.com/showthread...hreadid=544484



  #3   Report Post  
Posted to microsoft.public.excel.misc
dkipping
 
Posts: n/a
Default Check if workbook open


Sorry but I can't seem to make that work. The actual sub I'm using is as
below. Could you please alter to check if "Orders.xls" is open using
your routine.
Many thanks for your interest
David

Sub SaveOrder()
'
' SaveOrder Macro
' Macro recorded 19/05/2006 by David
'

'
Range("A1:M36").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Copy
Workbooks.Open Filename:="C:\My Documents\Orders\POTemp.xls"
ActiveSheet.Paste
Windows("Purchase Order.xls").Activate
Sheets("3").Select
Range("A2:M21").Select
Selection.Copy
Workbooks.Open Filename:="C:\My Documents\Orders\Orders.xls"
Sheets("Orders").Select
Range("A1").Select
Range("A1").End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Select
ActiveWorkbook.Save
ActiveWindow.Close
Windows("Purchase Order.XLS").Activate
Sheets("1").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("2").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Windows("POTemp.XLS").Activate
ActiveSheet.Shapes("Button 2").Select
Selection.Cut
ActiveSheet.Shapes("Button 1").Select
Selection.Cut
ChDir "C:\My Documents\Orders"
ActiveWorkbook.SaveAs Filename:= _
Range("h11"), FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False,
_
CreateBackup:=False
ActiveWorkbook.Close
Windows("Purchase Order.XLS").Activate
ActiveWorkbook.Close

End Sub


--
dkipping
------------------------------------------------------------------------
dkipping's Profile: http://www.excelforum.com/member.php...o&userid=34683
View this thread: http://www.excelforum.com/showthread...hreadid=544484

  #4   Report Post  
Posted to microsoft.public.excel.misc
Don Guillett
 
Posts: n/a
Default Check if workbook open


I would execute the macro I sent FIRST and then modify yours to remove the
selections.
This should get you going.

Sub copyfrom()
dwb = "workbooktocopyto.xls"
dws = "sheettocopyto"
swb = "worbooktocopyfrom.xls"
sws = "sheetctocopyfrom"

Windows(swb).Activate

'Sheets(sws).Range("b4:d4").Copy _
'Workbooks(dwb).Sheets(dws).Range("a15")

'Get Values ONLY without changing to values first
Workbooks(dwb).Sheets(dws).Range("b15:d15").Value = _
Sheets(sws).Range("b4:d4").Value

End Sub





--
Don Guillett
SalesAid Software

"dkipping" wrote in
message ...

Sorry but I can't seem to make that work. The actual sub I'm using is as
below. Could you please alter to check if "Orders.xls" is open using
your routine.
Many thanks for your interest
David

Sub SaveOrder()
'
' SaveOrder Macro
' Macro recorded 19/05/2006 by David
'

'
Range("A1:M36").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.Copy
Workbooks.Open Filename:="C:\My Documents\Orders\POTemp.xls"
ActiveSheet.Paste
Windows("Purchase Order.xls").Activate
Sheets("3").Select
Range("A2:M21").Select
Selection.Copy
Workbooks.Open Filename:="C:\My Documents\Orders\Orders.xls"
Sheets("Orders").Select
Range("A1").Select
Range("A1").End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Select
ActiveWorkbook.Save
ActiveWindow.Close
Windows("Purchase Order.XLS").Activate
Sheets("1").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("2").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Windows("POTemp.XLS").Activate
ActiveSheet.Shapes("Button 2").Select
Selection.Cut
ActiveSheet.Shapes("Button 1").Select
Selection.Cut
ChDir "C:\My Documents\Orders"
ActiveWorkbook.SaveAs Filename:= _
Range("h11"), FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False,
_
CreateBackup:=False
ActiveWorkbook.Close
Windows("Purchase Order.XLS").Activate
ActiveWorkbook.Close

End Sub


--
dkipping
------------------------------------------------------------------------
dkipping's Profile:
http://www.excelforum.com/member.php...o&userid=34683
View this thread: http://www.excelforum.com/showthread...hreadid=544484



  #5   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson
 
Posts: n/a
Default Check if workbook open

You could use a function like

Option Compare Text

Function IsWorkbookOpen(FileName As String) As Boolean
Dim WB As Workbook
For Each WB In Workbooks
If WB.Name = FileName Or _
WB.FullName = FileName Then
IsWorkbookOpen = True
Exit Function
End If
Next WB
IsWorkbookOpen = False
End Function


Then call this in your code

If IsWorkbookOpen("Book2.xls") = False Then


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"dkipping"
wrote in
message
...

Some macros I use require another workbook to open so I include
a line
like Workbooks.Open Filename:= C:\My\
Documents\Orders\POTemp.xls
The problem occurs when that workbook is already open - the
macro
stalls. Is there a way to bypass that instruction if the other
workbook is already open?


--
dkipping
------------------------------------------------------------------------
dkipping's Profile:
http://www.excelforum.com/member.php...o&userid=34683
View this thread:
http://www.excelforum.com/showthread...hreadid=544484





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
Calc status of open excel workbook should not overwrite another Michael Hill Setting up and Configuration of Excel 1 October 28th 05 06:48 PM
Excel 2003 hangs when trying to locate a workbook to open Darren Hill via OfficeKB.com Excel Discussion (Misc queries) 1 March 24th 05 12:41 PM
Excel workbook does not open in open window on desktop DeanH Excel Discussion (Misc queries) 2 March 8th 05 09:51 AM
Sumif Linking to Another Workbook error #VALUE! Tunde Excel Discussion (Misc queries) 16 March 4th 05 03:02 AM
Stubborn toolbars in Excel 007 Excel Discussion (Misc queries) 9 December 11th 04 02:02 PM


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