生成所有形状的特定尺寸,VBA和Excel

发布于 2025-02-09 09:52:18 字数 1369 浏览 1 评论 0原文

构建用于零件标签的QR生成器并试图证明发电机时,多个操作员可以在打印标签时使用它,以下代码:

生成QR码

与' function generateqr(qrcode_value作为字符串)

Dim URL As String
Dim My_Cell As Range

Set My_Cell = Application.Caller
URL = "https://chart.googleapis.com/chart?chs=100x100&&cht=qr&chl=" & qrcode_value
On Error Resume Next
  ActiveSheet.Pictures("My_QR_CODE_" & My_Cell.Address(False, False)).Delete
On Error GoTo 0
ActiveSheet.Pictures.Insert(URL).Select
With Selection.ShapeRange(1)
 .Name = "My_QR_CODE_" & My_Cell.Address(False, False)
 .Left = My_Cell.Left
 .Top = My_Cell.Top
End With
GenerateQR = ""

Set shapetocrop = ActiveSheet.Shapes.Range(Array("My_QR_CODE_A1"))
    With shapetocrop.Duplicate
        .ScaleHeight 1, True
        origHeight = .Height
        .Delete
    End With
croppoints = origHeight * 17 / 100
shapetocrop.PictureFormat.CropLeft = croppoints
shapetocrop.PictureFormat.CropRight = croppoints
shapetocrop.PictureFormat.CropTop = croppoints
shapetocrop.PictureFormat.CropBottom = croppoints

结束

函数 而且我可以在单独的表格上生成一个形状的大小,并具有以下内容:

Private Sub Worksheet_Calculate()
With ActiveSheet.Shapes.Range(Array(MY_QR_CODE_A1))
.Width = Range("F1").Value
.Height = Range("F1").Value
End With

End Sub

尝试复制此形状,更改单元格名称,我收到错误检测到的模棱两可的名称:worksheet_calculate()如何能如何我修复了吗?

Building a QR generator for part tags and trying to idiot proof the generator so multiple operators can use it when printing out tags, code below:

Generating the QR codes With

'
Function GenerateQR(qrcode_value As String)

Dim URL As String
Dim My_Cell As Range

Set My_Cell = Application.Caller
URL = "https://chart.googleapis.com/chart?chs=100x100&&cht=qr&chl=" & qrcode_value
On Error Resume Next
  ActiveSheet.Pictures("My_QR_CODE_" & My_Cell.Address(False, False)).Delete
On Error GoTo 0
ActiveSheet.Pictures.Insert(URL).Select
With Selection.ShapeRange(1)
 .Name = "My_QR_CODE_" & My_Cell.Address(False, False)
 .Left = My_Cell.Left
 .Top = My_Cell.Top
End With
GenerateQR = ""

Set shapetocrop = ActiveSheet.Shapes.Range(Array("My_QR_CODE_A1"))
    With shapetocrop.Duplicate
        .ScaleHeight 1, True
        origHeight = .Height
        .Delete
    End With
croppoints = origHeight * 17 / 100
shapetocrop.PictureFormat.CropLeft = croppoints
shapetocrop.PictureFormat.CropRight = croppoints
shapetocrop.PictureFormat.CropTop = croppoints
shapetocrop.PictureFormat.CropBottom = croppoints

End Function

`
And i can generate the size of one shape on a separate sheet with the following:

Private Sub Worksheet_Calculate()
With ActiveSheet.Shapes.Range(Array(MY_QR_CODE_A1))
.Width = Range("F1").Value
.Height = Range("F1").Value
End With

End Sub

When i attempt to replicate this, changing the cell name i get the error Ambiguous name detected: Worksheet_Calculate() how can i fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独自唱情﹋歌 2025-02-16 09:52:18

弄清楚了如何单独执行此操作,所以这里是代码

源:各种在线

Function GenerateQR(qrcode_value As String)

'生成QR'

Dim URL As String
Dim My_Cell As Range

Set My_Cell = Application.Caller
URL = "https://chart.googleapis.com/chart?chs=100x100&&cht=qr&chl=" & qrcode_value
'Uses Google API'
On Error Resume Next
  ActiveSheet.Pictures("My_QR_CODE_" & My_Cell.Address(False, False)).Delete
On Error GoTo 0
ActiveSheet.Pictures.Insert(URL).Select
With Selection.ShapeRange(1)
'Position the QR'
 .Name = "My_QR_CODE_" & My_Cell.Address(False, False)
 .Left = My_Cell.Left - 30
 .Top = My_Cell.Top - 10

 
End With
GenerateQR = ""
'Crop QR'
Set shapetocrop = ActiveSheet.Shapes.Range(Array("My_QR_CODE_" & My_Cell.Address(False, False)))
    With shapetocrop.Duplicate
        .ScaleHeight 0.8, True
        origHeight = .Height
        .Delete
    End With
    croppoints = origHeight * 17 / 100
    shapetocrop.PictureFormat.CropLeft = croppoints
    shapetocrop.PictureFormat.CropRight = croppoints
    shapetocrop.PictureFormat.CropTop = croppoints
    shapetocrop.PictureFormat.CropBottom = croppoints

结束函数

Figured out how to do this alone so here is the code

Source: Various online

Function GenerateQR(qrcode_value As String)

'Generating the QR'

Dim URL As String
Dim My_Cell As Range

Set My_Cell = Application.Caller
URL = "https://chart.googleapis.com/chart?chs=100x100&&cht=qr&chl=" & qrcode_value
'Uses Google API'
On Error Resume Next
  ActiveSheet.Pictures("My_QR_CODE_" & My_Cell.Address(False, False)).Delete
On Error GoTo 0
ActiveSheet.Pictures.Insert(URL).Select
With Selection.ShapeRange(1)
'Position the QR'
 .Name = "My_QR_CODE_" & My_Cell.Address(False, False)
 .Left = My_Cell.Left - 30
 .Top = My_Cell.Top - 10

 
End With
GenerateQR = ""
'Crop QR'
Set shapetocrop = ActiveSheet.Shapes.Range(Array("My_QR_CODE_" & My_Cell.Address(False, False)))
    With shapetocrop.Duplicate
        .ScaleHeight 0.8, True
        origHeight = .Height
        .Delete
    End With
    croppoints = origHeight * 17 / 100
    shapetocrop.PictureFormat.CropLeft = croppoints
    shapetocrop.PictureFormat.CropRight = croppoints
    shapetocrop.PictureFormat.CropTop = croppoints
    shapetocrop.PictureFormat.CropBottom = croppoints

End Function

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文