Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How to open a workbook?

I need to check if a workbook, named 2005q4, is open, and if not, open it
and filter the data, copy them to a worksheet in a different workbook (which
is open), and create a PivotTable. I have created my code assuming 2005q4 is
open, (may not be active). How can i open 2005q4 if it is not open, suppose
it is in the following path:

C:\Documents and Settings\ZZZ\My Documents\WorkRelatedExcel\[2005q4.xls]

Thank you in advance!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How to open a workbook?

Figured it out:

Workbooks.Open ("C:\Documents and Settings\ZZZ\My
Documents\WorkRelatedExcel\2005q4.xls")


"Desmond" wrote:

I need to check if a workbook, named 2005q4, is open, and if not, open it
and filter the data, copy them to a worksheet in a different workbook (which
is open), and create a PivotTable. I have created my code assuming 2005q4 is
open, (may not be active). How can i open 2005q4 if it is not open, suppose
it is in the following path:

C:\Documents and Settings\ZZZ\My Documents\WorkRelatedExcel\[2005q4.xls]

Thank you in advance!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How to open a workbook?

i intend to check if 2005q4 is open, if not, then open it.

Problems with the following code: it stops at the for loop; when 2005q4
opens, it still prompts a message asking me if i want to update links,
displayalerts set to false does not work in this kind of prompted message?

i = Workbooks.Count
For Each wk In Workbooks(i)
If wk.Name < "2005q4" Then
On Error Resume Next
Application.DisplayAlerts = False
Workbooks.Open ("C:\Documents and Settings\Mei FENG\My
Documents\Work Related Excel\2005q4.xls")
On Error GoTo 0
End If
Next



"Desmond" wrote:

Figured it out:

Workbooks.Open ("C:\Documents and Settings\ZZZ\My
Documents\WorkRelatedExcel\2005q4.xls")


"Desmond" wrote:

I need to check if a workbook, named 2005q4, is open, and if not, open it
and filter the data, copy them to a worksheet in a different workbook (which
is open), and create a PivotTable. I have created my code assuming 2005q4 is
open, (may not be active). How can i open 2005q4 if it is not open, suppose
it is in the following path:

C:\Documents and Settings\ZZZ\My Documents\WorkRelatedExcel\[2005q4.xls]

Thank you in advance!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default How to open a workbook?

The optional second parameter of Workbooks.Open is "UpdateLinks", so
Workbooks.Open (filename, False)
will open it without prompting and without updating. Change False to
True
if you do want to update links.


Desmond wrote:
i intend to check if 2005q4 is open, if not, then open it.

Problems with the following code: it stops at the for loop; when 2005q4
opens, it still prompts a message asking me if i want to update links,
displayalerts set to false does not work in this kind of prompted message?

i = Workbooks.Count
For Each wk In Workbooks(i)
If wk.Name < "2005q4" Then
On Error Resume Next
Application.DisplayAlerts = False
Workbooks.Open ("C:\Documents and Settings\Mei FENG\My
Documents\Work Related Excel\2005q4.xls")
On Error GoTo 0
End If
Next



"Desmond" wrote:

Figured it out:

Workbooks.Open ("C:\Documents and Settings\ZZZ\My
Documents\WorkRelatedExcel\2005q4.xls")


"Desmond" wrote:

I need to check if a workbook, named 2005q4, is open, and if not, open it
and filter the data, copy them to a worksheet in a different workbook (which
is open), and create a PivotTable. I have created my code assuming 2005q4 is
open, (may not be active). How can i open 2005q4 if it is not open, suppose
it is in the following path:

C:\Documents and Settings\ZZZ\My Documents\WorkRelatedExcel\[2005q4.xls]

Thank you in advance!


  #5   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default How to open a workbook?

Hi Desmond,

Here's a function you can use for this.

Function bBookIsOpen(wbkName) As Boolean
' Tests if the named workbook is open
'
' Arguments: wbkName [In] The name of the workbook.
'
' Returns: True if the workbook is open

Const sSource As String = "bBookIsOpen()"

Dim x As Workbook
On Error Resume Next 'ignore the error if the workbook isn't open
Set x = Workbooks(wbkName) 'perform the test
bBookIsOpen = (Err = 0) 'our return value is the result

End Function

This function will return FALSE if the book is not open. We check for this
to open the file using the "Not" operator, as follows:

If Not bBookIsOpen("2005q4.xls") Then 'open your workbook

'put the rest of your code here since it will now be open. (This assumes the
workbook exists in the specified folder) If it's already open, your code
skips the "Then" part and continues the procedure.

I also have a function to test if a file exists, if you're interested, that
is used in a similar fashion.

Regards, GS


"Desmond" wrote:

I need to check if a workbook, named 2005q4, is open, and if not, open it
and filter the data, copy them to a worksheet in a different workbook (which
is open), and create a PivotTable. I have created my code assuming 2005q4 is
open, (may not be active). How can i open 2005q4 if it is not open, suppose
it is in the following path:

C:\Documents and Settings\ZZZ\My Documents\WorkRelatedExcel\[2005q4.xls]

Thank you in advance!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How to open a workbook?

To Andrew and GS

Thank you very much for your help!

GS, could you also post your file test function please? Thanks in advance!

"GS" wrote:

Hi Desmond,

Here's a function you can use for this.

Function bBookIsOpen(wbkName) As Boolean
' Tests if the named workbook is open
'
' Arguments: wbkName [In] The name of the workbook.
'
' Returns: True if the workbook is open

Const sSource As String = "bBookIsOpen()"

Dim x As Workbook
On Error Resume Next 'ignore the error if the workbook isn't open
Set x = Workbooks(wbkName) 'perform the test
bBookIsOpen = (Err = 0) 'our return value is the result

End Function

This function will return FALSE if the book is not open. We check for this
to open the file using the "Not" operator, as follows:

If Not bBookIsOpen("2005q4.xls") Then 'open your workbook

'put the rest of your code here since it will now be open. (This assumes the
workbook exists in the specified folder) If it's already open, your code
skips the "Then" part and continues the procedure.

I also have a function to test if a file exists, if you're interested, that
is used in a similar fashion.

Regards, GS


"Desmond" wrote:

I need to check if a workbook, named 2005q4, is open, and if not, open it
and filter the data, copy them to a worksheet in a different workbook (which
is open), and create a PivotTable. I have created my code assuming 2005q4 is
open, (may not be active). How can i open 2005q4 if it is not open, suppose
it is in the following path:

C:\Documents and Settings\ZZZ\My Documents\WorkRelatedExcel\[2005q4.xls]

Thank you in advance!

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How to open a workbook?

The following code says syntax error:

Workbooks.Open ("C:\Documents and Settings\Mei FENG\My Documents\Work
Related Excel\2005q4.xls", False)

"Andrew Taylor" wrote:

The optional second parameter of Workbooks.Open is "UpdateLinks", so
Workbooks.Open (filename, False)
will open it without prompting and without updating. Change False to
True
if you do want to update links.


Desmond wrote:
i intend to check if 2005q4 is open, if not, then open it.

Problems with the following code: it stops at the for loop; when 2005q4
opens, it still prompts a message asking me if i want to update links,
displayalerts set to false does not work in this kind of prompted message?

i = Workbooks.Count
For Each wk In Workbooks(i)
If wk.Name < "2005q4" Then
On Error Resume Next
Application.DisplayAlerts = False
Workbooks.Open ("C:\Documents and Settings\Mei FENG\My
Documents\Work Related Excel\2005q4.xls")
On Error GoTo 0
End If
Next



"Desmond" wrote:

Figured it out:

Workbooks.Open ("C:\Documents and Settings\ZZZ\My
Documents\WorkRelatedExcel\2005q4.xls")


"Desmond" wrote:

I need to check if a workbook, named 2005q4, is open, and if not, open it
and filter the data, copy them to a worksheet in a different workbook (which
is open), and create a PivotTable. I have created my code assuming 2005q4 is
open, (may not be active). How can i open 2005q4 if it is not open, suppose
it is in the following path:

C:\Documents and Settings\ZZZ\My Documents\WorkRelatedExcel\[2005q4.xls]

Thank you in advance!



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to open a workbook?

Remove the parentheses.

--
Regards,
Tom Ogilvy


"Desmond" wrote in message
...
The following code says syntax error:

Workbooks.Open ("C:\Documents and Settings\Mei FENG\My Documents\Work
Related Excel\2005q4.xls", False)

"Andrew Taylor" wrote:

The optional second parameter of Workbooks.Open is "UpdateLinks", so
Workbooks.Open (filename, False)
will open it without prompting and without updating. Change False to
True
if you do want to update links.


Desmond wrote:
i intend to check if 2005q4 is open, if not, then open it.

Problems with the following code: it stops at the for loop; when

2005q4
opens, it still prompts a message asking me if i want to update links,
displayalerts set to false does not work in this kind of prompted

message?

i = Workbooks.Count
For Each wk In Workbooks(i)
If wk.Name < "2005q4" Then
On Error Resume Next
Application.DisplayAlerts = False
Workbooks.Open ("C:\Documents and Settings\Mei FENG\My
Documents\Work Related Excel\2005q4.xls")
On Error GoTo 0
End If
Next



"Desmond" wrote:

Figured it out:

Workbooks.Open ("C:\Documents and Settings\ZZZ\My
Documents\WorkRelatedExcel\2005q4.xls")


"Desmond" wrote:

I need to check if a workbook, named 2005q4, is open, and if not,

open it
and filter the data, copy them to a worksheet in a different

workbook (which
is open), and create a PivotTable. I have created my code assuming

2005q4 is
open, (may not be active). How can i open 2005q4 if it is not

open, suppose
it is in the following path:

C:\Documents and Settings\ZZZ\My

Documents\WorkRelatedExcel\[2005q4.xls]

Thank you in advance!





  #9   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default How to open a workbook?

Hi Desmond,

Thanks for the feedback, ..I'm glad to help!
Here's the function you asked for. I also included one for checking a valid
path. You can place them in any standard module. I keep them in
"MFunctions.bas" and drop it into my projects as a standard component.

Good luck! Code follows:

Function bFileExists(fileName) As Boolean
' Tests if the filename exists
'
' Arguments: fileName [In] The fullname of the file.
'
' Returns: True if the file (filename) exists

Const sSource As String = "bFileExists()"

On Error Resume Next 'ignore the error if the filename
doesn't exist
bFileExists = (Dir$(fileName) < "") 'our return value is the test result

End Function

Function bPathExists(sPath As String) As Boolean
' Tests if the named path to a directory (folder) exists
' "\nul" appended to the path makes it work with empty folders
'
' Arguments: sPath [In] The fullpath to the directory (folder).
'
' Returns: True if the path exists

Const sSource As String = "bPathExists()"

On Error Resume Next 'if the path doesn't exist
bPathExists = (Dir$(sPath & "\nul") < "") 'our return value is the
test result

End Function

Regards, GS

"Desmond" wrote:

To Andrew and GS

Thank you very much for your help!

GS, could you also post your file test function please? Thanks in advance!

"GS" wrote:

Hi Desmond,

Here's a function you can use for this.

Function bBookIsOpen(wbkName) As Boolean
' Tests if the named workbook is open
'
' Arguments: wbkName [In] The name of the workbook.
'
' Returns: True if the workbook is open

Const sSource As String = "bBookIsOpen()"

Dim x As Workbook
On Error Resume Next 'ignore the error if the workbook isn't open
Set x = Workbooks(wbkName) 'perform the test
bBookIsOpen = (Err = 0) 'our return value is the result

End Function

This function will return FALSE if the book is not open. We check for this
to open the file using the "Not" operator, as follows:

If Not bBookIsOpen("2005q4.xls") Then 'open your workbook

'put the rest of your code here since it will now be open. (This assumes the
workbook exists in the specified folder) If it's already open, your code
skips the "Then" part and continues the procedure.

I also have a function to test if a file exists, if you're interested, that
is used in a similar fashion.

Regards, GS


"Desmond" wrote:

I need to check if a workbook, named 2005q4, is open, and if not, open it
and filter the data, copy them to a worksheet in a different workbook (which
is open), and create a PivotTable. I have created my code assuming 2005q4 is
open, (may not be active). How can i open 2005q4 if it is not open, suppose
it is in the following path:

C:\Documents and Settings\ZZZ\My Documents\WorkRelatedExcel\[2005q4.xls]

Thank you in advance!

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
How to: Open closed workbook/Search data tables/Return data to open workbook Hugh Adams Excel Discussion (Misc queries) 0 August 18th 10 02:04 PM
Opening Excel, Book1 opens, remains open with other workbook open DanieB Excel Discussion (Misc queries) 0 September 3rd 09 08:23 AM
how do i open a data workbook when i open a timesheet workbook [email protected] uk Excel Discussion (Misc queries) 2 January 4th 09 04:50 PM
excel 2003 saved file will not open without a blank workbook open Bob Excel Discussion (Misc queries) 4 November 11th 06 04:24 PM
How do you program so that Workbook B cannot be open unless Workbook A is open? Plus I need to validation Marcello do Guzman[_3_] Excel Programming 2 December 5th 04 06:50 AM


All times are GMT +1. The time now is 09:23 AM.

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"