投稿日 | : 2003/03/29(Sat) 23:59 |
投稿者 | : 花ちゃん |
Eメール | : |
URL | : |
タイトル | : Re^3: VBからEXCELで選択されているセル範囲を取得したい |
エラーが出るコードを投稿して下さい(省略はしないで)
それとExcelのバージョン等の環境も忘れずに、又参照設定は何にしているのかも
下記を試して下さい。(参照設定は忘れずに)
Private Sub Command1_Click()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlApp.Visible = True
MsgBox "範囲を選択して下さい"
With xlApp.Selection
MsgBox "選択範囲は" & .Address & "です"
MsgBox "選択範囲は" & .Address(False, False) & "です"
MsgBox "選択範囲の左上のセルの行数は " & .Row & "行目,"
MsgBox "選択範囲の左上のセルの列数は " & .Columns(1).Column & "列目"
MsgBox "選択範囲の右下のセルの行数は " & .Rows(.Rows.Count).Row & "行目,"
MsgBox "選択範囲の右下のセルの列数は " & .Columns(.Columns.Count).Column & "列目"
MsgBox "選択範囲の右上のセルの行数は " & .Row & "行目,"
MsgBox "選択範囲の右上のセルの列数は " & .Columns(.Columns.Count).Column & "列目"
MsgBox "選択範囲の左下のセルの行数は " & .Rows(.Rows.Count).Row & "行目,"
MsgBox "選択範囲の左下のセルの列数は " & .Columns(1).Column & "列目"
End With
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End Sub