Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Opening / Closing files using Excel Macro?

Excel 2007 on XP Pro:
I am trying to write a a macro in Excel which will:
(1) open a workbook from another only if not already open
(2) close the workbook from another only if the other workbook is already
open.
Any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 896
Default Opening / Closing files using Excel Macro?

http://groups.google.pl/group/micros... 02811d5cf9d2

or Search for "is file open" in this NG


On 10 Lis, 12:28, Wes_A wrote:
Excel 2007 on XP Pro:
I am trying to write a a macro in Excel which will:
(1) open a workbook from another only if not already open
(2) close the workbook from another only if the other workbook is already
open.
Any ideas?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Opening / Closing files using Excel Macro?

Try using this function. I'm sure I got it from here at some point.

Option Explicit
Function OpenWorkbook() As Excel.Workbook
Dim sFile As String
Dim ShortName As String

Set OpenWorkbook = Nothing

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Title = "Please Select File to open"
If .Show = False Then Exit Function
sFile = .SelectedItems(1)
End With


ShortName = Right(sFile, Len(sFile) - InStrRev(sFile, "\"))



On Error Resume Next
Set OpenWorkbook = Workbooks(ShortName)
On Error Resume Next

If OpenWorkbook Is Nothing Then
Application.AutomationSecurity = msoAutomationSecurityLow
OpenWorkbook = Workbooks.Open(sFile)
Application.AutomationSecurity = msoAutomationSecurityByUI
End If

End Function
--
HTH,

Barb Reinhardt



"Wes_A" wrote:

Excel 2007 on XP Pro:
I am trying to write a a macro in Excel which will:
(1) open a workbook from another only if not already open
(2) close the workbook from another only if the other workbook is already
open.
Any ideas?

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
OPENING AND CLOSING OF EXCEL 07 FILES hot-rod-3 Excel Discussion (Misc queries) 2 July 23rd 09 12:30 AM
Opening and closing PDF files sus1e Excel Programming 0 February 19th 09 04:00 PM
Opening/Closing Large Files Nigel[_2_] Excel Programming 24 January 30th 08 06:46 AM
Excel 2003/2007 Crash when opening/closing files Richard NYC Excel Discussion (Misc queries) 1 October 18th 07 08:22 AM
Opening and closing text files Vince[_3_] Excel Programming 1 August 11th 03 09:43 PM


All times are GMT +1. The time now is 02:35 PM.

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"