+ Reply to Thread
Results 1 to 3 of 3

Macro error

  1. #1
    Registered User
    Join Date
    07-19-2018
    Location
    India
    MS-Off Ver
    2007
    Posts
    1

    Macro error

    I have created the below macro for exporting CATIA V5 2D drawing (dimensions, welding positions) to excel but I got the below error.

    Macros:
    #[CODE]
    Sub CATMain()

    Dim oDwgDoc1 As DrawingDocument

    On Error Resume Next Set oDwgDoc1 = CATIA.ActiveDocument If Err.Number <> 0 Then MsgBox ("The active document must be a drawing."), vbExclamation End End If On Error GoTo 0

    Dim oSel As Selection Set oSel = oDwgDoc1.Selection

    If oSel.Count < 1 Then MsgBox ("No dimensions selected."), vbExclamation End End If

    Dim oDwgDim As DrawingDimension Dim oInt As Integer Dim dblDims()

    Dim oTolType As Long Dim oTolName As String Dim oUpTol As String Dim oLowTol As String Dim odUpTol As Double Dim odLowTol As Double Dim oDisplayMode As Long

    For ctr = 1 To oSel.Count

    On Error Resume Next
    Set oDwgDim = oSel.Item(ctr).Value
    If Err.Number <> 0 Then MsgBox ("One of the selected elements is not a drawing dimension."), vbExclamation End End If On Error GoTo 0

    ReDim Preserve dblDims(3, ctr - 1)
    If oDwgDim.DimType = catDimAngle Or oDwgDim.DimType = catDimChamfer Then
    dblDims(0, ctr - 1) = oDwgDim.GetValue.Value * 57.2957795
    Else
    dblDims(0, ctr - 1) = oDwgDim.GetValue.Value
    End If
    oDwgDim.GetTolerances oTolType, oTolName, oUpTol, oLowTol, odUpTol, odLowTol, oDisplayMode
    dblDims(1, ctr - 1) = odUpTol
    dblDims(2, ctr - 1) = odLowTol
    dblDims(3, ctr - 1) = oDwgDim.Parent.Parent.Name
    odUpTol = 0
    odLowTol = 0
    Next

    Dim strFilePath As String Dim objFSO As Object Dim objStream As Object

    strFilePath = "C:\Users\Drew\Desktop\dimensions.csv" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objStream = objFSO.OpenTextFile(strFilePath, 8, True, 0)

    For i = 1 To oSel.Count objStream.WriteLine (dblDims(0, i - 1) & "," & dblDims(1, i - 1) & "," & dblDims(2, i - 1) & "," & dblDims(3, i - 1)) Next

    objStream.Close

    End Sub

    [CODE]

    Error:

    Source: Microsoft VB Script compilation error Description: Expected 'If' Statement: End Line: 9 Column: 15

    Can anyone help me out please
    Last edited by Shunmuga; 07-19-2018 at 03:09 AM.

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Macro error

    @ Shunmuga

    Welcome to the Forum, unfortunately your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    Please amend your first post to receive any further help
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Macro error

    This way it looks better but I can't tell if it works or not.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Sort Macro Run-time error '1004': Application/Object-defined error.
    By sam1212 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2014, 10:05 AM
  2. MACRO ERROR WITH EXCEL 2013 - Run-Time Error '-2147417848 (80010108)'
    By graiggoriz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-29-2014, 11:07 AM
  3. Excel macro (compile error. syntax error.) error
    By salar_younis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2014, 06:11 AM
  4. [SOLVED] Simple Calendar pop up macro --> error Run-time error '424': Object required
    By am_hawk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-11-2013, 10:38 AM
  5. Print Macro / module error & Update / Clear Macro error
    By mal.b.graham in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-28-2012, 06:40 PM
  6. [SOLVED] Macro error - Run time error 1004 (App defined/Object Defined error)
    By jlax34 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-06-2012, 03:02 PM
  7. Excel Macro Error - Run time error 1004 - Paste method of worksheet class failed
    By kvflynn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2012, 10:51 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1