我想在用户点击按钮时向用户显示分隔工作表中存在的某些信息。
我可以将Excel设置为在该范围的起始行“转到”此工作表,但我找不到隐藏其他所有内容的方法。
是否有一些方法,或者我是否必须隐藏所有行和列?
答案 0 :(得分:3)
在工作簿的VB项目中插入UserForm。
将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
从而提供范围内未格式化的数据:
答案 1 :(得分:2)
要将范围导出为图像,可以在UserForm中创建图像而不是列表框。那么这应该足以让你开始。
从这个截图中可以看出,图像可能并不总是非常清晰。此外,如果您正在使用大量单元格,图像可能不适合您的用户形式等。我会留下您的部分内容:)
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
答案 2 :(得分:0)
如果您record a macro
并手动隐藏了一些列和行,则会为您生成代码,您将看到它是如何完成的。