電子書籍の厳選無料作品が豊富!

VB6.0で開発しています。
以下のようにクラスモジュールを作ったのですが
フォームでコマンドボタンを押したら
処理されるようにしたいのですが
どうすればいいかわかりません。
教えてください。
Class CExcel
Public App
Public WshShell
Public ErrDescription
Private WorkBook
Public CurBook

Private Sub Class_Initialize()
Call InitSetting()
End Sub
Private Sub Class_Terminate()
Call Quit()
End Sub

Public Default Function InitSetting()
if IsEmpty( App ) then
Set App = CreateObject("Excel.Application")
end if
if IsEmpty( WshShell ) then
Set WshShell = CreateObject("WScript.Shell")
end if
App.DisplayAlerts = False
Set CurBook = Nothing
end function

Public Function Quit()
If not IsEmpty( App ) Then
For Each Workbook In App.Workbooks
WorkBook.Saved = True
Next
App.Quit
Set App = Nothing
App = Empty
Set CurBook = Nothing
End If
End Function

Public Property Let Visible( bFlg )
App.Visible = bFlg
End Property
Public Property Get Visible
Visible = App.Visible
End Property
Public Function Open( strPath )
on error resume next
Set Open = App.Workbooks.Open(strPath)
if Err.Number <> 0 then
Set Open = Nothing
ErrDescription = Err.Description
Exit Function
end if
on error goto 0
Set CurBook = Open
' アクティブなウィンドウを最大化
App.ActiveWindow.WindowState = xlMaximized
End Function

Public Function Create( strPath )
Dim nBooks
App.Workbooks.Add
nBooks = App.Workbooks.Count
Set Create = App.Workbooks( nBooks )
Set CurBook = Create
CurBook.Activate
App.ActiveWindow.WindowState = xlMaximized
if strPath <> "" then
on error resume next
CurBook.SaveAs( strPath )
if Err.Number <> 0 then
MsgBox( Err.Description )
Exit Function
end if
on error goto 0
end if
End Function

Public Function Close( MyBook )
if IsObject( MyBook ) then
MyBook.Saved = True
MyBook.Close
Set MyBook = Nothing
MyBook = Empty
else
if CurBook is Nothing then
else
CurBook.Saved = True
CurBook.Close
Set CurBook = Nothing
end if
end if
End Function

Function Save( MyBook )
if IsObject( MyBook ) then
MyBook.Save
else
CurBook.Save
end if
End Function

Function SaveAs( MyBook, strPath )
if IsObject( MyBook ) then
MyBook.SaveAs strPath
else
CurBook.SaveAs strPath
end if
End Function

Function Load( strPath )
if not IsEmpty( App ) then
MsgBox( "Excel をロードする前に、Quitを実行して下さい   " )
Exit Function
end if
Call WshShell.Run( _
"RunDLL32.EXE shell32.dll,ShellExec_RunDLL " & _
strPath _
)
End Function
End Class

A 回答 (2件)

ソースは全部読みませんでした。


クラスの使い方の簡単な例を

クラスジュールに貼付け(オブジェクト名:Class1)
Option Explicit
Public Function test(a As Integer, b As Integer) As Integer
   test = a + b
End Function

標準モジュールに貼り付け

Option Explicit
Sub Sample()
Dim M As New Class1
Dim x As Integer
Dim y As Integer
x = 1
y = 2
MsgBox M.test(x, y)
End Sub

標準モジュールのSampleを実行すれば、1+3の計算を実行します。
参考になるでしょうか?
    • good
    • 0

>処理されるようにしたいのですが


>どうすればいいかわかりません。

なにをどのように処理したいのでしょうか?
クラスの利用方法がわからないのでしょうか?

この回答への補足

はい、利用方法がわかりません。

補足日時:2007/03/15 12:24
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!