text from excel into autocad problem with distance between lines of text that come in

Discussion in 'AutoCAD' started by tombates, Jan 31, 2006.

  1. tombates

    tombates Guest

    I am trying to export text from excel into autocad. I have been able
    to achieve this task.
    I specified the distance between lines and the text height.
    The first line comes in at a point twice the y distance from where I
    specified. Subsequent lines come in correctly at the distance
    specified.
    What am I doing wrong?
    ------
    Dim dist As Double
    Dim dist1 As Double
    Dim textstring As String
    Dim height1 As Double
    Dim excel As Object
    Dim inspt As Variant
    Dim lastrow As Long
    Dim rng As Range
    Dim endrow
    Dim endcol
    Dim begrow
    Dim begcol
    Dim acad As Object
    Private Sub CommandButton1_Click()
    Set excel = GetObject(, "Excel.Application")
    If Err <> 0 Then

    Err.Clear
    Set excel = CreateObject("Excel.Application")
    If Err <> 0 Then
    MsgBox "Could not load Excel.", vbExclamation
    End
    End If
    End If

    On Error GoTo 0
    excel.Visible = True
    excel.Sheets("Sheet1").Select
    Set excelsheet = excel.ActiveWorkbook.Sheets("Sheet1")
    Set rng = excel.Application.InputBox(Prompt:="Select range", Type:=8)
    begrow = rng(1).Row
    begcol = rng(1).Column
    endrow = rng(rng.Count).Row
    endcol = rng(rng.Count).Column
    excelacadform.Hide
    Set acad = GetObject(, "autocad.Application")
    height1 = ThisDrawing.Utility.GetReal("text height: ")
    dist1 = ThisDrawing.Utility.GetReal("space between lines: ")

    PtFlag1 = True
    col = begcol
    rownum = begrow

    While PtFlag1 = True

    inspt = ThisDrawing.Utility.GetPoint(, "Enter a point: ")
    'inspt(1) = inspt(1) - dist

    PtFlag = True
    rownum = 1
    dist = 0


    While PtFlag = True

    textstring = excelsheet.Cells(rownum, col).Value
    'inspt(1) = inspt(1) - dist
    Set textObj = ThisDrawing.ModelSpace.AddText(textstring, inspt,
    height1)
    textObj.HorizontalAlignment = acHorizontalAlignmentMiddle
    textObj.TextAlignmentPoint = inspt

    inspt(1) = inspt(1) - dist

    rownum = rownum + 1
    dist = dist1
    'inspt(1) = inspt(1) - dist
    If rownum = (endrow + 1) Then PtFlag = False
    'inspt(1) = inspt(1) - dist

    Wend
    col = col + 1
    'inspt(1) = inspt(1) - dist

    If col = (endcol + 1) Then PtFlag1 = False
    'inspt(1) = inspt(1) - dist


    Wend
    End Sub
     
    tombates, Jan 31, 2006
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.