Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Pearson,
Please see the code that I posted for Barb on the same thread. I copied your code right after: Set NewSht = ThisWorkbook.ActiveSheet and I replace the folder directory just as you instructed; however, there is one section of the code that turn RED: Res = MsgBox("The file '" & FName & "' is already open." & vbCrLf & _ "Click 'Yes' to close and re-open the workbook." & vbCrLf & _ "Click 'No' to skip this workbook and leave the existing version open." & vbCrLf & _ "Click 'Cancel' to terminate the operation.", vbYesNoCancel, "Open Workbooks") And when I run it, here is the Error message I got: Complie error: Automation type not supported in Visual Basic Any idea? FYI, I'm using Office 2004 for Mac OSX. Thank you, Neon520 "Chip Pearson" wrote: Try some code like the following. Change the FolderName line marked with <<< to the appropriate folder. The code will open all the files in that folder. If a file is already open, the user is prompted to close and re-open the file (vbYes), skip the file and leave it open (vbNo) or terminate the entire operation (vbCancel). Sub OpenFiles() Dim WB As Workbook Dim FName As String Dim SaveDir As String Dim FolderName As String Dim Res As VbMsgBoxResult FolderName = "C:\SiteStats" '<<< CHANGE ChDrive FolderName ChDir FolderName FName = Dir("*.xls") On Error Resume Next Do Until FName = vbNullString Err.Clear Set WB = Nothing Set WB = Workbooks(FName) If Err.Number = 0 Then ' workbook already open Res = MsgBox("The file '" & FName & "' is already open." & vbCrLf & _ "Click 'Yes' to close and re-open the workbook." & vbCrLf & _ "Click 'No' to skip this workbook and leave the existing version open." & vbCrLf & _ "Click 'Cancel' to terminate the operation.", vbYesNoCancel, "Open Workbooks") Select Case Res Case vbYes Workbooks(FName).Close savechanges:=True Case vbNo ' do nothing Case vbCancel Exit Sub End Select Else Application.Workbooks.Open FName Debug.Print "OPEN: " & FName End If FName = Dir() Loop ChDrive SaveDir ChDir SaveDir End Sub Cordially, Chip Pearson Microsoft MVP Excel Product Group Pearson Software Consulting, LLC www.cpearson.com (email on web site) On Sun, 21 Dec 2008 09:45:00 -0800, Neon520 wrote: Hi Everyone, Thanks to Joel, I have a code to open All Files in one folder to extract the data from. However, Debugging Error will occur if any of the file in That folder remain open, regardless of any changes made and/or user save the changes or not. Is there a way to code so that there will an ERROR MESSAGE BOX appear when any of the file in That folder is open. Then the user can click ok and then close the file manually. I know there must be a way to force save the opened file and proceed with whatever is next, but this way might force save any unintended changes save to it. So I rather prefer it to be manual instead. Thanks for any help. Neon520 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Open Excel file get error with file names that have spaces in the | Setting up and Configuration of Excel | |||
Error 55 File Already Open | Excel Programming | |||
EXCEL:Can't open any file without error saying it's ALREADY open??? | Excel Worksheet Functions | |||
open file file then error message | Excel Discussion (Misc queries) | |||
hyperlink error: "Cannot open the specified file" | Excel Worksheet Functions |