Syntax error in VBA [closed]

closed . This question needs details or to be clearer and is not currently accepting answers.

want to improve this question? Add details and make it clearer what problem is being solved by editing this post .

Closed 5 years ago .

improve this question

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
Author: Matheus Pombo, 2016-01-18

1 answers

Well, the error is just code indentation and a pretty simple thing in VBA for 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
 0
Author: StillBuggin, 2016-01-18 01:55:38