ユーザーがボタンをクリックするたびに、別のワークシートに存在する特定の情報をユーザーに表示したいと考えています。
範囲の開始行でこのワークシートに「移動」するように Excel を設定できますが、他のすべてを非表示にする方法が見つかりませんでした。
これには何らかの方法がありますか、それともすべての行と列を非表示にする必要がありますか?
ワークブックの VB プロジェクトにユーザー フォームを挿入します。
ユーザーフォームに ListBox コントロールを追加します。
UserForm_Activate
次に、イベント コードで次のコードのようなことを行います。
Private Sub UserForm_Activate()
Dim tbl As Range
Set tbl = Range("B2:E7") '## Change this to capture the rang you need '
Me.Caption = "Displaying data from " & _
ActiveSheet.Name & "!" & tbl.Address
With ListBox1
.ColumnHeads = False
.ColumnCount = tbl.Columns.Count
.RowSource = tbl.Address
End With
End Sub
範囲からのフォーマットされていないデータを提供します:
範囲を画像としてエクスポートするには、リストボックスの代わりにユーザーフォームで画像を作成できます。次に、これで十分に開始できます。
このスクリーンショットからわかるように、画像は常に鮮明に表示されるとは限りません。また、広範囲のセルで作業している場合、画像がユーザーフォームに収まらないなどの可能性があります。その部分を理解するのはあなた次第です:)
Private Sub UserForm_Activate()
Dim tbl As Range
Dim imgPath As String
Set tbl = Range("B2:E7") '## Change this to capture the rang you need '
imgPath = Export_Range_Images(tbl)
Caption = "Displaying data from " & _
ActiveSheet.Name & "!" & tbl.Address
With Image1
If Not imgPath = vbNullString Then
.Picture = LoadPicture(imgPath)
.PictureSizeMode = fmPictureSizeModeClip
.PictureAlignment = 2 'Center
.PictureTiling = False
.SpecialEffect = 2 'Sunken
End If
End With
End Sub
Function Export_Range_Images(rng As Range) As String
'## Modified by David Zemens with
' credit to: _
' http://vbadud.blogspot.com/2010/06/how-to-save-excel-range-as-image-using.html ##'
Dim ocht As Object
Dim srs As Series
rng.CopyPicture xlScreen, xlPicture
ActiveSheet.Paste
Set ocht = ActiveSheet.Shapes.AddChart
For Each srs In ocht.Chart.SeriesCollection
srs.Delete
Next
'## Modify this line as needed ##'
fname = "C:\users\david_zemens\desktop\picture.jpg"
On Error Resume Next
Kill fname
On Error GoTo 0
ocht.Width = rng.Width
ocht.Height = rng.Height
ocht.Chart.Paste
ocht.Chart.Export Filename:=fname, FilterName:="JPG"
Application.DisplayAlerts = False
ocht.Delete
Application.DisplayAlerts = True
Set ocht = Nothing
Export_Range_Images = fname
End Function