• ベストアンサー

VB2005でのEXCEL処理で警告が消えません

いつもお世話になっております。 私はVB2005入門者です。 EXCELで処理を行っております。 処理事態は完了するのですが 下記のコードの後半部の警告がどうやっても潰せないので 修正方法のアドバイスをお願いします。 Dim xlApp As Excel.Application Dim xlBooks As Excel.Workbooks Dim xlBook As Excel.Workbook Dim xlSheets As Excel.Sheets Dim xlSheet As Excel.Worksheet ' 必要な変数は Try の外で宣言する Try ' 必要な変数は Try の中でインスタンス化する xlApp = New Excel.Application() xlBooks = xlApp.Workbooks xlBook = xlBooks.Open("C\:hoge0.xls") xlSheets = xlBook.Worksheets xlBook.Worksheets(1).Range("F4") = shhoge(0) xlBook.Worksheets(1).Range("I4") = shhoge(0) xlBook.Worksheets(1).Range("K4") = shhoge(5) xlBook.Worksheets(1).Range("M5") = shhoge(0) xlBook.Worksheets(1).Range("O4") = shhoge(1) xlBook.Worksheets(1).Range("R4") = shhoge(1) xlBook.Worksheets(1).Range("U5") = shhoge(1) xlBook.Worksheets(1).Range("T5") = shhoge(2) xlBook.Worksheets(1).Range("W5") = shhoge(3) xlBook.Worksheets(1).Range("X5") = shhoge(4) ' シートのカウントが 1 より大きければシートを削除する If xlSheets.Count > 1 Then ' Display アラートを消す xlApp.DisplayAlerts = False ' シートを削除する xlSheet = DirectCast(xlSheets(2), Excel.Worksheet) xlSheet.Delete() End If ' 1000 ミリ秒 (1秒) 待機する System.Threading.Thread.Sleep(1000) ' Excel ブックを保存する xlApp.DisplayAlerts = False xlBook.SaveAs("C:\hoge.xls") ' Microsoft Excel を終了する xlApp.Quit() Finally ' 参照したオブジェクトをすべて解放する If Not xlSheet Is Nothing Then   ←[警告]値が割り当てられる前に使用されています。 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) End If If Not xlSheets Is Nothing Then   ←[警告]値が割り当てられる前に使用されています。 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets) End If If Not xlBook Is Nothing Then   ←[警告]値が割り当てられる前に使用されています。 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook) End If If Not xlBooks Is Nothing Then   ←[警告]値が割り当てられる前に使用されています。 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks) End If If Not xlApp Is Nothing Then   ←[警告]値が割り当てられる前に使用されています。 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) End If End Try Form2.Show() End Sub

  • npupu
  • お礼率68% (41/60)

質問者が選んだベストアンサー

  • ベストアンサー
noname#259269
noname#259269
回答No.1

放っておいても実害はありませんが、 Dim xlBooks As Excel.Workbooks = Nothing のように、変数定義時に Nothing を入れておけばよいですよ。

npupu
質問者

お礼

Dim xlApp As Excel.Application = Nothing Dim xlBooks As Excel.Workbooks = Nothing Dim xlBook As Excel.Workbook = Nothing Dim xlSheets As Excel.Sheets = Nothing Dim xlSheet As Excel.Worksheet = Nothing これでなくなりました! 実害はないのですね。きちんと覚えておきます! ありがとうございました

その他の回答 (1)

回答No.2

例えば以下のようなプログラムがあった場合を考えてみてください。 Dim aa As TextBox Dim bb As Boolean = False If Not bb Then aa = New TextBox aa.Name = "hoge" End If MessageBox.Show(aa.Name) もしbbがtrueだった場合aaはnewされず、aaには値が割り振られる前に使用されることになり、NullReferenceExceptionが発生します。 要はコーディングする上での作法が悪いですよ、という警告です。 解決するにはNo1さんのように初期値を設定する。 または、どのようにプログラムが流れても値が設定されたうえで参照されるようにコードを記述することです。

npupu
質問者

お礼

非常に参考になりました。 最近VBがいっそう楽しくなったので今後とも よろしくお願いします!(?)

関連するQ&A

  • VB2005でのEXCELマクロ操作

    お世話になっております。 VB2005から指定したEXCELファイルを開き、標準モジュールにあるマクロを起動したいと考えております。 調べたところ、Runメソッドを使用するようですが、マクロファイルを開くところで停止してしまいます。 以下にソースを書きましたので、アドバイス頂きたいと思います。 Dim n As Short Dim xlApp As Excel.Application = Nothing Dim xlBooks As Excel.Workbooks = Nothing Dim xlBook As Excel.Workbook = Nothing Dim xlSheets As Excel.Sheets = Nothing Dim xlSheet As Excel.Worksheet = Nothing Dim xlRange As Excel.Range = Nothing Dim Fname As String = "C:\Documents and Settings\hoge\Application Data\Microsoft\Excel\XLSTART\PERSONAL.XLS" '読み込むファイル Try xlApp = New Excel.Application() xlBooks = xlApp.Workbooks For n = 0 To fil.Length - 1 xlBook = xlBooks.Open(fil(n)) xlSheets = xlBook.Worksheets xlApp.Run("'" & Fname & "'!module2.DB処理", fil(n)) '引数をもつ処理の呼び出し方法 '1000ミリ秒(1秒)待機する System.Threading.Thread.Sleep(1000) ' Excel ブックを保存する xlApp.DisplayAlerts = False xlBook.Save() Next ' Microsoft Excel を終了する xlApp.Quit() Finally If Not xlSheet Is Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) End If If Not xlSheets Is Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets) End If If Not xlBook Is Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook) End If If Not xlBooks Is Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks) End If If Not xlApp Is Nothing Then System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) End If End Try

  • EXCELのプロセスに関して

    教えて下さい。 VB2008でEXCELを操作しようと考えていますが、以下のような記述をした場合、 EXCELのプロセスが残ってしまいます。 いろいろ調査し、いらない部分を削除した結果、以下のところまで絞込みを行い、 ****のところを削除した場合、問題なくプロセスは終了した為、****印の中の記述が 原因というところまで絞れました。 単純にブックの中のシートをコピーで追加しているだけですが、何がどのようにすれば プロセスは残らずに消えてくれるでしょうか。。。 よろしくお願いします。 《記述内容》 '既存のEXCELファイルを開く Dim xlFilePath As String = "C:\test.xls" '起動時の処理 Dim xlApp As New Excel.Application Dim xlBooks As Excel.Workbooks = xlApp.Workbooks Dim xlBook As Excel.Workbook = xlBooks.Open(xlFilePath) xlApp.Visible = True ' 確認のためExcelのウィンドウを表示する Dim xlSheets As Excel.Sheets = xlBook.Worksheets Dim xlSheet As Excel.Worksheet = CType(xlSheets.Item(1), Excel.Worksheet) ************************* xlSheet = xlSheets.Item(1) 'シートの選択 xlSheet.Copy(After:=xlBook.Worksheets(1)) 'シートのコピー xlSheet = xlSheets.Item(2) '再度シートを選択 xlSheet.Name = "zz" 'シートに名前を付ける ************************* xlBooks.Close() xlApp.DisplayAlerts = False xlApp.Quit() ' COM オブジェクトの解放 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) ' Excel のプロセス終了 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)

  • EXCELファイルからの値取得に関して

    環境:Visual Basic 2008 教えて下さい。 画面上から2つのEXCELファイルを指定し、1回の処理でその2つの EXCELからそれぞれ値を取得したいと考えています。 その為、以下のような記述をしましたが、2回目の値取得のところで "オブジェクト参照がオブジェクト インスタンスに設定されていません。" というエラーメッセージとなってしまいます。 1つのファイルから取得する事は経験ありましたが、同時に2回は初めてで ある為、記述方法が正しいのか、、、 どのように記述したら良いかを教えて下さい。 初歩的な質問で申し訳ありませんが、よろしくお願いします。 《記述内容》 'EXCELファイルを開く Dim xlFilePath As String = ofd1.FileName '起動時の処理 Dim xlApp As Object xlApp = CreateObject("Excel.Application") Dim xlBooks As Object = xlApp.Workbooks Dim xlBook As Object = xlBooks.Open(xlFilePath) '現シート数 Dim S_COUNT As Integer = xlBook.Worksheets.Count Dim xlSheets As Object = xlBook.Worksheets Dim xlSheet As Object = CType(xlSheets.Item(1), Object) '現シート数 S_COUNT = xlBook.Worksheets.Count Dim R_名称 As String R_名称 = "" R_名称 = xlSheet.Cells(1, 1).Value 'COM オブジェクトの解放 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks) 'Excel のプロセス終了 xlApp.DisplayAlerts = False xlApp.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) GC.Collect() 'のEXCELファイルを開く Dim xlFilePath2 As String = ofd2.FileName '起動時の処理 Dim xlApp2 As Object xlApp2 = CreateObject("Excel.Application") Dim xlBooks2 As Object = xlApp2.Workbooks Dim xlBook2 As Object = xlBooks2.Open(xlFilePath2) '現シート数 Dim S_COUNT2 As Integer = xlBook2.Worksheets.Count Dim xlSheets2 As Object = xlBook2.Worksheets Dim xlSheet2 As Object = CType(xlSheets2.Item(1), Object) '現シート数 S_COUNT = xlBook2.Worksheets.Count Dim R_番号 As String R_番号 = "" R_番号 = xlSheet2.Cells(I_COUNT2, 1).Value 'COM オブジェクトの解放 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks) 'Excel のプロセス終了 xlApp.DisplayAlerts = False xlApp.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) GC.Collect()

  • VB.NETからEXCELの起動が、うまくいかない

    3回目の同じ質問になってしまうのですがよろしくお願いいたします。 下記のようなソースでEXCELファイルを作成し、その後ファイルを開くという処理をしています。 Dim xlApp As New Excel.Application Dim xlBooks As Excel.Workbooks = xlApp.Workbooks Dim xlBook As Excel.Workbook = xlBooks.Add Dim xlSheets As Excel.Sheets = xlBook.Worksheets Dim xlSheet As Excel.Worksheet = xlSheets.Item(1) Dim xlRange As Excel.Range Dim xlCells As Excel.Range = xlSheet.Cells xlRange = xlCells(1, 10) xlRange.Value = "--" xlRange = xlCells(1, 5) xlCells.EntireColumn.AutoFit() xlBook.SaveAs(sPath & "\" & sFileName, Excel.XlFileFormat.xlWorkbookNormal) System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlCells) System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlRange) System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlSheet) System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlSheets) xlCells = Nothing xlRange = Nothing xlSheet = Nothing xlSheets = Nothing xlBook.Close() System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlBook) System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlBooks) xlBook = Nothing xlBooks = Nothing xlApp.Quit() System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xlApp) xlApp = Nothing GC.Collect() System.Diagnostics.Process.Start(sPath & "\" & sFileName) ある特定のPCでのみEXCELのメニューバーとステータスバーのみしか表示されない状態です。 起動部分(Process.Start)をコメントアウトして確認したところ GC.COLLECTでEXCELが終了することなく、アプリの終了時にEXCELが終了する 状態にあります。 これはオブジェクトの開放がうまくいっていないのでしょうか? よろしくお願いいたします。

  • EXCELのプロセスに関して2

    教えて下さい。 先日もEXCELに関して投稿させて頂きましたが、やはり少しソースを変更すると、最終的に EXCELのプロセスが残ってしまいます。 前回は、記述の最後に、"GC.Collect"を追加するようにご指摘頂き、余計なメモリを解放する事で、 プロセスは残らないようになりましたが、今回は、以下の記述のように、発注先コードが違った場合、 シートを分けるという事をしたい為、以下のような記述をした際に、プロセスが残ってしまう現象が 発生しました。 切り分けを行った結果、やはり*****印の部分があるかないかで、プロセスが残る現象が発生しますが、 何かプロセスを残してしまうような記述をしているのでしょうか。。。 どなたか教えて頂ければ幸いです。 よろしくお願いします。 《記述内容》 '既存のEXCELファイルを開く Dim xlFilePath As String = "C:\order.xls" '起動時の処理 Dim xlApp As New Excel.Application Dim xlBooks As Excel.Workbooks = xlApp.Workbooks Dim xlBook As Excel.Workbook = xlBooks.Open(xlFilePath) '確認のためExcelのウィンドウを表示する xlApp.Visible = True Dim xlSheets As Excel.Sheets = xlBook.Worksheets Dim xlSheet As Excel.Worksheet = CType(xlSheets.Item(1), Excel.Worksheet) 'シートの選択 xlSheet = xlSheets.Item(1) 'シートのコピー xlSheet.Copy(After:=xlBook.Worksheets(1)) '再度シートを選択 xlSheet = xlSheets.Item(2) 'シートに名前を付ける xlSheet.Name = "zz" Dim x, y As Integer x = 0 y = 0 Dim mcount As Integer Dim fcount As Integer Dim D_発注先コード As String D_発注先コード = h_date(0).IN_発注先コード Dim strDat(14, 14) As Object For icount As Integer = 0 To count - 1 If D_発注先コード <> h_date(icount).IN_発注先コード Then 'データをEXCELファイルに書き出し Dim xlRange As Excel.Range 'データの入力セル範囲 xlRange = xlSheet.Range("A17:O31") 'セルへデータの入力 xlRange.Value = strDat System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange) D_発注先コード = h_date(icount).IN_発注先コード x = 0 *********************************************************************** xlSheet = xlSheets.Item(1) 'シートの選択 xlSheet.Copy(After:=xlBook.Worksheets(2)) 'シートのコピー xlSheet = xlSheets.Item(3) '再度シートを選択 xlSheet.Name = "YY" 'シートに名前を付ける *********************************************************************** strDat(x, 1) = h_date(icount).IN_指示納期 strDat(x, 2) = h_date(icount).IN_発注番号 fcount = 1 Else strDat(x, 1) = h_date(icount).IN_指示納期 strDat(x, 2) = h_date(icount).IN_発注番号 End If x = x + 1 Next Dim xlRange3 As Excel.Range 'データの入力セル範囲 xlRange3 = xlSheet.Range("A17:O31") 'セルへデータの入力 xlRange3.Value = strDat 'COM オブジェクトの解放 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange3) xlBooks.Close() xlApp.DisplayAlerts = False xlApp.Quit() 'COM オブジェクトの解放 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets) 'Excel のプロセス終了 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) GC.Collect()

  • VB2008でのExcelオブジェクトの宣言と解放

    下記のようなコードを書きました。 Public Sub XXXXXXXXXXX Dim xlApp As New Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As New Excel.Worksheet try xlApp = CreateObject("Excel.Application") xlApp.Workbooks.Open(Filename:=excelTempPath, UpdateLinks:=0) xlBook = DirectCast((xlApp.Workbooks.Open(excelTempPath)), Excel.Workbook) シートのコピー、削除など操作 xlBook.Close(SaveChanges:=True, Filename:=strExcelPath) xlApp.Quit() Finally MRComObject(xlSheet) MRComObject(xlBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) xlApp = Nothing End Try End Sub Public Sub MRComObject(Of T As Class)(ByRef objCom As T, Optional ByVal force As Boolean = False) If objCom Is Nothing Then Return End If Try If System.Runtime.InteropServices.Marshal.IsComObject(objCom) Then If force Then System.Runtime.InteropServices.Marshal.FinalReleaseComObject(objCom) Else Dim count As Integer = System.Runtime.InteropServices.Marshal.ReleaseComObject(objCom) End If End If Finally objCom = Nothing End Try End Sub MRComObject(xlBook)でコンパイルの警告が出力されるのですが 回避する方法はないのでしょうか。

  • VB2008からのEXCEL出力に関して

    VB2008にて開発を行っていますが、その中で、あるデータをEXCELに出力するような 処理を行いたいと考えています。 その際に、ホームページ等で検索を行いながら、以下のような記述をしましたが、やはり 中身を完全に理解していない為、あまり応用がききません。。。 以下の内容で、1シート目までの出力は正しく行われ、問題なくプロセスも残らずに終了 する事ができました。 ただし、指定の行(10行目)までデータが書き込まれたら、1シートを追加して 次のシートに記載するというようなループ処理を考えていますが、どのように記述したら 良いでしょうか。。。。 どこまでをループ対象にすれば良いかが。。。 教えて下さい。 よろしくお願いします。 《記述内容》 '既存のEXCELファイルを開く Dim xlFilePath As String = "C:\order.xls" '起動時の処理 Dim xlApp As New Excel.Application Dim xlBooks As Excel.Workbooks = xlApp.Workbooks Dim xlBook As Excel.Workbook = xlBooks.Open(xlFilePath) xlApp.Visible = True ' 確認のためExcelのウィンドウを表示する Dim xlSheets As Excel.Sheets = xlBook.Worksheets Dim xlSheet As Excel.Worksheet = CType(xlSheets.Item(1), Excel.Worksheet) Dim x, y As Integer x = 0 y = 0 'データをEXCELファイルに書き出し Dim xlRange As Excel.Range Dim strDat(14, 14) As Object xlRange = xlSheet.Range("A17:O31") 'データの入力セル範囲 Do While x < count strDat(x, 1) = h_date(x).IN_指示納期 strDat(x, 2) = h_date(x).IN_発注番号 strDat(x, 5) = h_date(x).IN_品目名称 strDat(x, 8) = h_date(x).IN_メーカー名 strDat(x, 9) = h_date(x).IN_数量 strDat(x, 10) = h_date(x).IN_単価 strDat(x, 11) = h_date(x).IN_金額 strDat(x, 12) = h_date(x).IN_備考 xlRange.Value = strDat 'セルへデータの入力 x = x + 1 Loop 'System.Runtime.InteropServices.Marshal.ReleaseComObject(strDat) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange) xlBooks.Close() xlApp.DisplayAlerts = False xlApp.Quit() ' COM オブジェクトの解放 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) ' Excel のプロセス終了 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)

  • エクセルの開放

    VB2008でエクセルを操作しているのですが、エクセルのプロセスが残ってしまってどうやって解放すればいいのかわかりません。 サンプルプログラム-------------- Dim xlApp As New Excel.Application Dim xlBooks As Excel.Workbooks = xlApp.Workbooks Dim xlBook As Excel.Workbook = xlBooks.Add Dim xlSheets As Excel.Sheets = xlBook.Worksheets Dim xlSheet As Excel.Worksheet = xlSheets.Item(1) Dim xlobj As Object '開放用 xlobj = xlSheet.Range("A1:C3") xlobj.Value = "TEST" MRComObject(xlobj) MRComObject(xlSheet) MRComObject(xlSheets) xlBook.Close(False) MRComObject(xlBook) MRComObject(xlBooks) xlApp.Quit() MRComObject(xlApp) MRComObjectでCOM オブジェクトへの参照を解放しています。 このプログラムでは特に問題ないのですが、 xlobj = xlApp.Worksheets("Sheet2") xlobj2 = xlobj.Range("A1:C2") xlobj2.Value = "TEST" のようにワークシートを指定すると解放できません。 xlSheet = xlBook.Worksheets("Sheet2") としてもプロセスが残ります。 またVB6.0では可能だった xlApp.Worksheets("Sheet2").Select() のようにワークシートを切り替えるときもVB2008ではプロセスが残ってしまいます。 これはどのようにしたら解決するのでしょうか?

  • vb.netでExcelの1行をコピーしたい

    WindowsXP(SP2) VB2005 Excel2007で開発を行っております。 Excelの操作について質問したいことがあり、投稿しました。 Excelシートの横一列をセル単位に罫線で囲み、その行を必要な行数分どんどん下にコピーしたいのですが、コピーの部分で行き詰ってしまいました。 以下がコードです。 ' Excel用Objectの宣言 Public Shared xl As Excel.Application Public Shared xlBooks As Excel.Workbooks Public Shared xlBook As Excel.Workbook Public Shared xlSheets As Excel.Sheets Public Shared xlSheet As Excel.Worksheet Public Shared xlBorders As Excel.Borders Public Shared xlCells As Excel.Range ' ユーザID x = 1 y = 1 ' 罫線で囲む xlBorders = xlSheet.Range(xlSheet.Cells(y, x), xlSheet.Cells(y, x)).Borders xlBorders.LineStyle = Excel.XlLineStyle.xlContinuous System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBorders) xlBorders = Nothing ' 住所 x = 2 y = 1 ' 罫線で囲む xlBorders = xlSheet.Range(xlSheet.Cells(y, x), xlSheet.Cells(y, x)).Borders xlBorders.LineStyle = Excel.XlLineStyle.xlContinuous System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBorders) xlBorders = Nothing ' 氏名 x = 3 y = 1 ' 罫線で囲む xlBorders = xlSheet.Range(xlSheet.Cells(y, x), xlSheet.Cells(y, x)).Borders xlBorders.LineStyle = Excel.XlLineStyle.xlContinuous System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBorders) xlBorders = Nothing ' Tel x = 4 y = 1 ' 罫線で囲む xlBorders = xlSheet.Range(xlSheet.Cells(y, x), xlSheet.Cells(y, x)).Borders xlBorders.LineStyle = Excel.XlLineStyle.xlContinuous System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBorders) xlBorders = Nothing ' 備考 x = 5 y = 1 ' 罫線で囲む xlBorders = xlSheet.Range(xlSheet.Cells(y, x), xlSheet.Cells(y, x)).Borders xlBorders.LineStyle = Excel.XlLineStyle.xlContinuous System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBorders) xlBorders = Nothing Dim i As Int16 For i = 0 To 15 ' ここでコピーの処理を行う Next 以上がコードとなります。 どなたかご教授をよろしくお願いします。

  • VB2005でExcelのシートをコピー

    VB2005Expressで開発をしています。 Excelのシートをコピーして同じbookに追加をしたいと思っています。 下記でまずExcelを使用できるようにして  Dim xlApp As New Excel.Application  Dim xlBooks As Excel.Workbooks = xlApp.Workbooks  Dim xlBook As Excel.Workbook = xlBooks.Add '新規のファイルを開く  Dim xlSheets As Excel.Sheets = xlBook.Worksheets  Dim xlSheet As Excel.Worksheet = xlSheets.Item(1)  xlApp.Visible = True 下記で追加できると思うのですが、()内にセットするパラメータが わかりません・・・  xlBook.Worksheets.Copy() どなたかご存知の方がいらっしゃいましたら教えて下さい。 よろしくお願いします。

専門家に質問してみよう