E灵11.5版开始开发二维码接口,只要您安装了E灵正式版,那么就可以通过VBA调用E灵的二维码接口,自行控制二维码的生成方式。

调用E灵的二维码接口语法如下:
Application.COMAddIns.Item("Eling").Object.ma "二维码内容",高度(单位:厘米) , 单元格, 边距(单位:磅)
说明:
1.过程名称 Ma,完整书写方式是:Application.COMAddIns.Item("Eling").Object.ma
2.它有四个参数,第一参数是生成二维码的值,文本格式,例如“中华人民共和国”或者Range("a1").value
3.第二参数是二维码的存放位置,用单元格表示,例如Range("b2").
4.第三参数是二维码的高度,以厘米为单位
5.第四参数是二维码的边距,值为是0时表示靠边,值为2表示上边距为2(单位是磅)。

代码举例
1.用"20190325-24" 生成3厘米高的二维码,放在C3单元格中
Sub 生成单个二维码()
  Application.COMAddIns.Item("Eling").Object.ma "20190325-24", 3, Range("c3"), 2
End Sub


2.用订单号码、型体名称、单位和数量批量生成二码
Sub 批量生成二维码()
  Dim cell As Range, RowItem As Integer, Mysrt As String, Eling As Object
  Set Eling = Application.COMAddIns.Item("Eling").Object
  Application.ScreenUpdating = False
  With Range("a2:d10") '根据自己的情况修改范围
    For RowItem = 1 To .Rows.Count
      Mysrt = ""
      For Each cell In .Rows(RowItem).Cells
       If Len(cell.Value) > 0 Then Mysrt = Mysrt & "," & cell.Value
      Next cell
      Eling.ma Mid(Mysrt, 2, 999), 1.5, Cells(RowItem + 1, "E"), 2
    Next RowItem
    Application.ScreenUpdating = True
    MsgBox "生成完毕,一共" & .Rows.Count & "个二维码", vbOKOnly, "提示"
  End With
End Sub

3.用订单号码、型体名称、单位和数量批量生成二维码
Sub 批量生成含标题的二维码()
  Dim cell As Range, RowItem As Integer, ColCount As Byte, Mysrt As String, Eling As Object
  Set Eling = Application.COMAddIns.Item("Eling").Object
  Application.ScreenUpdating = False
  With Range("a2:d10") '根据自己的情况修改范围
    For RowItem = 1 To .Rows.Count
      Mysrt = "": ColCount = 0
      For Each cell In .Rows(RowItem).Cells
        ColCount = ColCount + 1
        Mysrt = Mysrt & vbCrLf & Cells(1, ColCount) & ":" & cell.Value
      Next cell
      Eling.ma Mid(Mysrt, 3, 999), 1.5, Cells(RowItem + 1, "E"), 2
    Next RowItem
    Application.ScreenUpdating = True
    MsgBox "生成完毕,一共" & .Rows.Count & "个二维码", vbOKOnly, "提示"
  End With
End Sub

下载案例文件