1/11/2024 0 Comments Winzip activation code 19.5If String.Equals(current.Name, wbName, StringComparison.InvariantCulture) Then Public Shared Function WorkbookNameInUse(wbName As String, excelApplication As .Application) As Boolean If String.Equals(current.FullName, fi.FullName, StringComparison.InvariantCulture) Then Try ' this just ensures that current is set = Nothing OpenWorkbooks = excelApplication.Workbooks Public Shared Function WorkbookIsOpen(fi As System.IO.FileInfo, excelApplication As .Application) As Booleanĭim current As .Workbookĭim openWorkbooks As .Workbooks ' alert user and/or do whatever is apropriate MessageBox.Show("Another workbook file with the same name is already open") If WorkbookNameInUse(inputInfo.Name, ExcelGlobal_definst) Then WkbCurrent = ExcelGlobal_definst.Workbooks(inputInfo.Name) MessageBox.Show("workbook is already open") If WorkbookIsOpen(inputInfo, ExcelGlobal_definst) Then ' check if the Workbook is already open in the Excel Instance ' you have these variable defined elsewhere, defined here just to show what I think they areĭim wkbCurrent As .Workbookĭim ExcelGlobal_definst As .Applicationĭim inputInfo As New System.IO.FileInfo(InputFileName) ' the FileInfo object replaces the need for a FileSystemObject Then you switch to use GetObject to do what? In this statement, "wkbCurrent = ExcelGlobal_(Filename:=InputFileName)", you are using an existing Excel instance to open a Workbook. What do you expect this GetObject call to do?ĭo you want to create a new Excel application instance opened to the Workbook contained in InputFileName? Or do you just want to open the InputFileName WorkBook under the existing Excel instance? The code is too confusing in its mixing of methods to obtain object instances for me to understand your intent. The Class parameter would be something like: "Excel.Application", "Excel.Sheet", "Excel.Chart", etc. You are passing the variable ExcelFileName that presumably has a form of SomeWorkBookName.Extension where Extension is xls/xlsm/xlsb. The type or class of object to create.As I stated previously, you are passing an invalid string as the Class parameter to the GetObject Method. The name of the application providing the object. Msg = Where & "Error " & Err.Number & " - " & Err.DescriptionĮnd Sub.note a line is commented out where I have been trying various ways around the problem.Īppname: Required. 'objExcel = GetObject(PathName, (VB6.GetItemString(1, 0))) ObjExcel = GetObject(InputFileName, ExcelFileName) WkbCurrent = ExcelGlobal_definst.Workbooks(ExcelFileName) WkbCurrent = ExcelGlobal_(Filename:=InputFileName) Throw VbMakeException(vbErrors.OLEFileNotFound)Ĭode: Private Sub cmdLdInputFile_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLdInputFile.Clickĭim PathName As String = Input_Default_Path & "\" Throw VbMakeException(vbErrors.CantCreateObject) 'Only works for Com2 objects, not for COM+ objects.Ĭatch ex As Code: Public Function GetObject(Optional ByVal PathName As String = Nothing, Optional ByVal As String = Nothing) As Object
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |