![]() |
Test that a workbook is open
Hi,
I have a macro that I want to start with a paste command (data copied from another system) but only if the following conditions are met: 1 There is a worksheet open 2 It is empty 3 The first two columns have been formatted as text. I can do (2), and can set the columns to text before the paste - so can do (3). Can anyone help me with a test to ensure there is a worksheet open (a user might press the icon I set up when there is no workbook open) Thanks, Gef |
Test that a workbook is open
Hi
try something like the following (I assume you mean a workbook and not a worksheet) sub foo() dim wbk as workbook on error resume next set wbk = workbooks("your_workbookname.xls") if err.number<0 then msgbox "Workbook is not open" exit sub end if 'now your other code end sub -- Regards Frank Kabel Frankfurt, Germany "Gef" schrieb im Newsbeitrag ... Hi, I have a macro that I want to start with a paste command (data copied from another system) but only if the following conditions are met: 1 There is a worksheet open 2 It is empty 3 The first two columns have been formatted as text. I can do (2), and can set the columns to text before the paste - so can do (3). Can anyone help me with a test to ensure there is a worksheet open (a user might press the icon I set up when there is no workbook open) Thanks, Gef |
Test that a workbook is open
Heres one approach:
Sub test() If Not ActiveWindow Is Nothing Then If Not ActiveWindow.ActiveSheet Is Nothing Then MsgBox "OK!" End If End If End Sub -- Rob van Gelder - http://www.vangelder.co.nz/excel "Gef" wrote in message ... Hi, I have a macro that I want to start with a paste command (data copied from another system) but only if the following conditions are met: 1 There is a worksheet open 2 It is empty 3 The first two columns have been formatted as text. I can do (2), and can set the columns to text before the paste - so can do (3). Can anyone help me with a test to ensure there is a worksheet open (a user might press the icon I set up when there is no workbook open) Thanks, Gef |
All times are GMT +1. The time now is 11:34 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com