![](http://oshiete.xgoo.jp/images/v2/pc/qa/question_title.png?e8efa67)
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件)
- 最新から表示
- 回答順に表示
No.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の計算を実行します。
参考になるでしょうか?
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
似たような質問が見つかりました
- Excel(エクセル) 2つのVBAを一緒にしたら機能しなくなりました(エクセル) 7 2022/06/02 12:41
- Visual Basic(VBA) ExcelのVBAコードについて教えてください。 1 2023/02/02 09:25
- Visual Basic(VBA) 【追加】ファイルを閉じてダイアログで保存した時だけ処理の実行をする 3 2022/03/23 15:43
- Visual Basic(VBA) ExcelのVBAコードについて教えてください。 1 2023/08/09 10:33
- Excel(エクセル) エクセルVBAでオブジェクトが必要です 2 2022/09/10 16:37
- Visual Basic(VBA) VBAでの共有パスにつきまして 1 2023/03/04 17:24
- Visual Basic(VBA) EXCEL VBAにて動的にCheckBOXを複数作成し、同BOXにイベントを追加したい 1 2023/03/16 07:05
- Visual Basic(VBA) いつもお世話になっております、VBAで教えて頂きたいのですが 2 2022/05/05 22:20
- Visual Basic(VBA) VBAの繰り返し処理について教えてください。 3 2022/08/02 13:21
- Visual Basic(VBA) 【VBAエラー】Nextに対するForがありません 対策について 5 2022/11/21 21:26
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
レコードセットにnullの場合
-
タイムアウトする仕組みを作りたい
-
subsequentとnextの違いってな...
-
Verilog-HDLによる設計において
-
verilogのcase文
-
VB.NETでのイベントの途中終了
-
VBAでcallで呼び出したsubを終...
-
C言語のサフィックスについて
-
C#のループでtextboxに値を入れ...
-
アクセスできない保護レベルエ...
-
vb.net 文字コードから漢字へ変換
-
他のフォームから別のフォーム...
-
パーソナルXLSBのfuctionを呼び...
-
VBAで入力数値について
-
WORd VBA 文章を単語に分解する
-
エクセルVBAでテキストボッ...
-
ACCESS VBA 文字抽出について ...
-
リストビューの列ヘッダーの幅...
-
構造体のコピー
-
入力された値の動的取得方法に...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
レコードセットにnullの場合
-
タイムアウトする仕組みを作りたい
-
subsequentとnextの違いってな...
-
verilogのcase文
-
日付の重複
-
vbsのmsgboxランダム表示について
-
リスト間のアイテム移動について
-
TreeViewのTag情報取得
-
pascalでの二分探索(バイナリ...
-
delphi
-
Pascalのプログラムです
-
C言語のプログラムで...
-
【FPGA】VHDLのprocessとevent
-
エクセルVBAついて ①if•••••the...
-
FORTRAN77でプログラミング
-
クラスモジュールの処理
-
EXCEL VBA 文字 アドレス 検...
-
パスカル言語
-
Verilog-HDLによる設計において
-
なんで? cEn-P^-1AP=P^-1(cEn-AP)
おすすめ情報