Hi.
I have a VB Program that displays excel spreadsheet only the first time but if you close this file and open another spreadsheet file, it won't display data. What's wrong. Appreciate to any help you can give me. Thanks.
Form :
Option Explicit
Private Sub Command1_Click()
Set xlAPP = Nothing
Set xlSht = Nothing
excel_load
End Sub
Module :
Public xlSht As Object
Public xlAPP As excel.Application
Public xlBook As Object
Public xlDocName As String
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Sub xl_open(xl_fn As String)
Workbooks.Open (xl_fn)
End Sub
Public Sub xl_dia()
' Set CancelError is True
Form1.cdlxl.CancelError = True
On Error GoTo OpenErr
Form1.cdlxl.DialogTitle = "Open SpreadSheet"
Form1.cdlxl.InitDir = "e:\estimating\es-share"
Form1.cdlxl.Filter = "MS Excel (*.xls)|*.xls"
Form1.cdlxl.ShowOpen
OpenErr:
'User pressed the Cancel button
xlDocName = Form1.cdlxl.FileName
Exit Sub
End Sub
Public Sub excel_load()
xl_dia
Dim lResult As Long
lResult = FindWindow(vbNullString, "excel"
If lResult > 0 Then
lResult = ShowWindow(lResult, SW_RESTORE)
Else
If xlDocName <> "" Then
On Error Resume Next
Set xlAPP = GetObject("", "Excel.Application"
If Err Then
Set xlAPP = CreateObject("", "Excel.Application"
Err.Clear
End If
On Error Resume Next
If Err Then
MsgBox "could Not Load Excel.", vbExclamation
End
Else
xlAPP.Visible = True
xl_open (xlDocName)
'xl_select "Active Projects"
'xlAPP.Workbooks.Activate
'xlSht.Activate
End If
End If
End If
End Sub
Public Function IsAppRunning() As Boolean
Dim objExcel As excel.Application
On Error Resume Next
Set objExcel = Nothing
Set objExcel = GetObject(, "Excel.Application"
IsAppRunning = (Err.Number = 0)
If Not IsAppRunning Then
End If
Err.Clear
End Function
I have a VB Program that displays excel spreadsheet only the first time but if you close this file and open another spreadsheet file, it won't display data. What's wrong. Appreciate to any help you can give me. Thanks.
Form :
Option Explicit
Private Sub Command1_Click()
Set xlAPP = Nothing
Set xlSht = Nothing
excel_load
End Sub
Module :
Public xlSht As Object
Public xlAPP As excel.Application
Public xlBook As Object
Public xlDocName As String
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Sub xl_open(xl_fn As String)
Workbooks.Open (xl_fn)
End Sub
Public Sub xl_dia()
' Set CancelError is True
Form1.cdlxl.CancelError = True
On Error GoTo OpenErr
Form1.cdlxl.DialogTitle = "Open SpreadSheet"
Form1.cdlxl.InitDir = "e:\estimating\es-share"
Form1.cdlxl.Filter = "MS Excel (*.xls)|*.xls"
Form1.cdlxl.ShowOpen
OpenErr:
'User pressed the Cancel button
xlDocName = Form1.cdlxl.FileName
Exit Sub
End Sub
Public Sub excel_load()
xl_dia
Dim lResult As Long
lResult = FindWindow(vbNullString, "excel"
If lResult > 0 Then
lResult = ShowWindow(lResult, SW_RESTORE)
Else
If xlDocName <> "" Then
On Error Resume Next
Set xlAPP = GetObject("", "Excel.Application"
If Err Then
Set xlAPP = CreateObject("", "Excel.Application"
Err.Clear
End If
On Error Resume Next
If Err Then
MsgBox "could Not Load Excel.", vbExclamation
End
Else
xlAPP.Visible = True
xl_open (xlDocName)
'xl_select "Active Projects"
'xlAPP.Workbooks.Activate
'xlSht.Activate
End If
End If
End If
End Sub
Public Function IsAppRunning() As Boolean
Dim objExcel As excel.Application
On Error Resume Next
Set objExcel = Nothing
Set objExcel = GetObject(, "Excel.Application"
IsAppRunning = (Err.Number = 0)
If Not IsAppRunning Then
End If
Err.Clear
End Function