Syntax error in VBA [closed]

2

I need help to solve a syntax error in Visual Basic Excel, the command is as follows:

Application.ScreenUpdating = False

Dim wsh As Worksheet
Set wsh = Excel.ActiveSheet

Dim data As String
Dim r As Long 'The row index
r = 1
Do
  data = wsh.Cells(r, 1) 'A1, A2, A3...
  If Len(data) = 0 Then Exit Sub 'The code stops at the first empty cell

  Dim rng As Range
  Set rng = wsh.Cells(r, 2) 'Placing barcodes into B1, B2, B3...

  Dim shp As Shape
  Set shp = wsh.Shapes.AddOLEObject("STROKESCRIBE.StrokeScribeCtrl.1")

  shp.LockAspectRatio = msoFalse
  shp.Width = rng.Width
  shp.Height = rng.Height
  shp.Left = rng.Left
  shp.Top = rng.Top

  Dim barcode As StrokeScribe
  Set barcode = shp.OLEFormat.Object.Object

  barcode.Alphabet = QRCODE
  barcode.Text = data

  If barcode.Error Then
    MsgBox barcode.ErrorDescription
    Exit Do
  End If
  r = r + 1
Loop
Application.ScreenUpdating = True
How to find and modify existing barcode objects
Dim sh As Shape
Dim ss As StrokeScribe

Dim wsh As Worksheet
Set wsh = Excel.ActiveSheet

For Each sh In wsh.Shapes
  If sh.Type = msoOLEControlObject And sh.OLEFormat.progID = "STROKESCRIBE.StrokeScribeCtrl.1" Then
      Set ss = sh.OLEFormat.Object.Object
      ss.Alphabet = DATAMATRIX
      ss.Text = "1234ABCD"
  End If
Next
    
asked by anonymous 18.01.2016 / 02:20

1 answer

0

Well, the error is only code indentation and a very simple thing in VBA to Excel: you have to put everything inside a sub routine

.

Sub exemplo()
'comeco da subrotina
Application.ScreenUpdating = False

'declara variaveis
Dim wsh As Worksheet
Set wsh = Excel.ActiveSheet
Dim data As String
Dim r As Long 'The row index
r = 1
'loop
Do
    data = wsh.Cells(r, 1) 'A1, A2, A3...
    If Len(data) = 0 Then Exit Sub 'The code stops at the first empty cell
    'declara variaveis
    Dim rng As Range
    Set rng = wsh.Cells(r, 2) 'Placing barcodes into B1, B2, B3...
    Dim shp As Shape
    Set shp = wsh.Shapes.AddOLEObject("STROKESCRIBE.StrokeScribeCtrl.1")
        
    shp.LockAspectRatio = msoFalse
    shp.Width = rng.Width
    shp.Height = rng.Height
    shp.Left = rng.Left
    shp.Top = rng.Top
        
    Dim barcode As StrokeScribe
    Set barcode = shp.OLEFormat.Object.Object
        
    barcode.Alphabet = QRCODE
    barcode.Text = data
    
    If barcode.Error Then MsgBox
        barcode.ErrorDescription
        Exit Do
    End If
    r = r + 1
Loop
Application.ScreenUpdating = True

Dim sh As Shape
Dim ss As StrokeScribe
Dim wsh As Worksheet
Set wsh = Excel.ActiveSheet
    
For Each sh In wsh.Shapes
    If sh.Type = msoOLEControlObject And sh.OLEFormat.progID = "STROKESCRIBE.StrokeScribeCtrl.1" Then Set ss = sh.OLEFormat.Object.Object
        ss.Alphabet = DATAMATRIX
        ss.Text = "1234ABCD"
    End If
Next
'fim da subrotina
End Sub
    
18.01.2016 / 02:48