在 Microsoft 中打开一个 png 文件作为弹出图像的评论背景 Excel
Open a png file to put as a comment background for a pop up image in Microsoft Excel
我正在尝试根据 excel sheet 中的某个字段添加评论背景。该字段包含 .png 文件的文件名。
这是在 Mac.
这里我之前创建了一个在评论中添加图片的宏:
Sub InsertPic()
'
' InsertPic Macro
'
' Keyboard Shortcut: Option+Cmd+p
strFileToOpen = Application.GetOpenFilename
MsgBox strFileToOpen
ActiveCell.AddComment
With ActiveCell.Comment.Shape
.ScaleWidth 5, msoFalse, msoScaleFromTopLeft
.ScaleHeight 5, msoFalse, msoScaleFromTopLeft
.Fill.UserPicture strFileToOpen
End With
End Sub
这里它打开了一个带有 GetOpenFilename
的对话框,但现在我想循环获取文件名。如果我把一个文件名放在一个字符串中
strFileToOpen = "/path/FileName.png"
内存不足!有什么线索吗?
更新:
您需要添加引用 Microsoft Scripting Runtime 才能使用变量类型 "Scripting.FileSystemObject".
这对我有用
Sub InsertPic()
'
' InsertPic Macro
'
' Keyboard Shortcut: Option+Cmd+p
Dim FileExists As Variant
Dim FileSystemLibrary As New Scripting.FileSystemObject
On Error GoTo Err01InsertPic
Set FileExists = FileSystemLibrary.GetFile(ActiveCell.Value)
ActiveCell.AddComment
With ActiveCell.Comment.Shape
.ScaleWidth 5, msoFalse, msoScaleFromTopLeft
.ScaleHeight 5, msoFalse, msoScaleFromTopLeft
.Fill.UserPicture FileExists
End With
If 1 = 2 Then ' 99. If error
Err01InsertPic:
MsgBox ("Picture " & ActiveCell.Value & " doesn't exists!"), vbCritical
End If ' 99. If error
End Sub
我正在尝试根据 excel sheet 中的某个字段添加评论背景。该字段包含 .png 文件的文件名。
这是在 Mac.
这里我之前创建了一个在评论中添加图片的宏:
Sub InsertPic()
'
' InsertPic Macro
'
' Keyboard Shortcut: Option+Cmd+p
strFileToOpen = Application.GetOpenFilename
MsgBox strFileToOpen
ActiveCell.AddComment
With ActiveCell.Comment.Shape
.ScaleWidth 5, msoFalse, msoScaleFromTopLeft
.ScaleHeight 5, msoFalse, msoScaleFromTopLeft
.Fill.UserPicture strFileToOpen
End With
End Sub
这里它打开了一个带有 GetOpenFilename
的对话框,但现在我想循环获取文件名。如果我把一个文件名放在一个字符串中
strFileToOpen = "/path/FileName.png"
内存不足!有什么线索吗?
更新:
这对我有用
Sub InsertPic()
'
' InsertPic Macro
'
' Keyboard Shortcut: Option+Cmd+p
Dim FileExists As Variant
Dim FileSystemLibrary As New Scripting.FileSystemObject
On Error GoTo Err01InsertPic
Set FileExists = FileSystemLibrary.GetFile(ActiveCell.Value)
ActiveCell.AddComment
With ActiveCell.Comment.Shape
.ScaleWidth 5, msoFalse, msoScaleFromTopLeft
.ScaleHeight 5, msoFalse, msoScaleFromTopLeft
.Fill.UserPicture FileExists
End With
If 1 = 2 Then ' 99. If error
Err01InsertPic:
MsgBox ("Picture " & ActiveCell.Value & " doesn't exists!"), vbCritical
End If ' 99. If error
End Sub