Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 39

Thread: Solved: Creating tables with Word.Application issue (II)

  1. #1

    Solved: Creating tables with Word.Application issue (II)

    My second time request for help under the same title. And I have put all togher everyting that I have collected on the first posting.
    I am NOT a professional at VB6 BUT I am willing to listen and follow any ideas.
    Please be patient.
    The error I received is "Object variable or With block variable not set".
    Please advice.
    Thanks.



    [vba]
    Option Explicit
    Dim Tbl As Table
    Dim objApp As Word.Application

    Private Sub Form_Load()

    With objApp
    .Selection.Font.Bold = True
    .Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Selection.TypeText Text:="How are you"
    .Selection.TypeText Text:=vbCrLf
    .Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
    End With

    Set Tbl = ActiveDocument.Tables.Add(Range:=Selection.Range, _
    NumRows:=4, NumColumns:=2)
    Tbl.Range.Font.Bold = True
    Tbl.Columns(1).Width = 20
    Tbl.Cell(1, 1).Range.Text = "AAA"
    Tbl.Cell(1, 2).Range.Text = "111"
    Tbl.Cell(2, 1).Range.Text = "BBB"
    Tbl.Cell(2, 2).Range.Text = "222"
    Tbl.Cell(3, 1).Range.Text = "CCC"
    Tbl.Cell(3, 2).Range.Text = "333"
    Tbl.Cell(4, 1).Range.Text = "DDD"
    Tbl.Cell(4, 2).Range.Text = "444"

    With objApp
    .Selection.Font.Bold = True
    .Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
    .Selection.TypeText Text:=vbCrLf
    .Selection.TypeText Text:="Thank you!"
    End With
    objApp.ActiveDocument.SaveAs FileName:="c:\test\test1.doc"

    Set objApp = Nothing
    End Sub

    [/vba]

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Mr. Doubtfire,

    I'm no word expert but this seems to be the problem at the beginning of the script. Not sure why your using a private sub to begin with but thats not the problem. I think you need to define your variables within the routine. Also define the objApp as an Object then set a value(not sure if value is the right term) for it like this.
    [VBA]
    Option Explicit
    Sub Form_Load()
    Dim Tbl As Table
    Dim objApp As Object
    Set objApp = Word.Application

    [/VBA]

    I hope this helps get you going in the right direction. I'm pretty sure one of the board word coders will come along soon and help you with this.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Hi Mr. Doubtfire,

    I think you have it correct except for 1 statement.

    [VBA]
    Private Sub Form_Load()

    Set objApp = New Word.Application '<- this is what is missing
    With objApp
    .Selection.Font.Bold = True
    .Selection.ParagraphFormat.Alignment = _
    wdAlignParagraphCenter
    .Selection.TypeText Text:="How are you"
    .Selection.TypeText Text:=vbCrLf
    .Selection.ParagraphFormat.Alignment = _
    wdAlignParagraphLeft
    End With

    [/VBA]

    Hey lucas

  4. #4
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I was wrong, but this will work for you sorry about misinforming you earlier

    [VBA]

    Private Sub Form_Load()
    Set objApp = New Word.application
    objApp.Documents.Open _
    "C:\Documents and Settings\Administrator\Desktop\test.doc"
    With objApp
    .Selection.Font.Bold = True
    .Selection.ParagraphFormat.Alignment = _
    wdAlignParagraphCenter
    .Selection.TypeText Text:="How are you"
    .Selection.TypeText Text:=vbCrLf
    .Selection.ParagraphFormat.Alignment = _
    wdAlignParagraphLeft
    End With

    Set Tbl = ActiveDocument.Tables.Add(Range:=Selection.Range, _
    NumRows:=4, NumColumns:=2)
    Tbl.Range.Font.Bold = True
    Tbl.Columns(1).Width = 20
    Tbl.Cell(1, 1).Range.Text = "AAA"
    Tbl.Cell(1, 2).Range.Text = "111"
    Tbl.Cell(2, 1).Range.Text = "BBB"
    Tbl.Cell(2, 2).Range.Text = "222"
    Tbl.Cell(3, 1).Range.Text = "CCC"
    Tbl.Cell(3, 2).Range.Text = "333"
    Tbl.Cell(4, 1).Range.Text = "DDD"
    Tbl.Cell(4, 2).Range.Text = "444"

    With objApp
    .Selection.Font.Bold = True
    .Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
    .Selection.TypeText Text:=vbCrLf
    .Selection.TypeText Text:="Thank you!"
    End With


    objApp.ActiveDocument.SaveAs FileName:="c:test1.doc"
    objApp.ActiveDocument.Close False
    objApp.Quit False
    Set objApp = Nothing
    End Sub



    [/VBA]

  5. #5
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Actually there is one other potential error here:

    [VBA]
    Option Explicit

    Private Sub Form_Load()
    Dim Tbl As Table
    Dim objApp As Word.application


    Set
    objApp = New Word.application
    objApp.Documents.Open "C:\Documents and Settings\Administrator\Desktoptest.doc"

    With objApp
    .Selection.Font.Bold = True
    .Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Selection.TypeText Text:="How are you"
    .Selection.TypeText Text:=vbCrLf
    .Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
    End With

    Set Tbl = objApp.ActiveDocument.Tables.Add(Range:=Selection.Range, _
    NumRows:=4, NumColumns:=2)
    Tbl.Range.Font.Bold = True
    Tbl.Columns(1).Width = 20
    Tbl.Cell(1, 1).Range.Text = "AAA"
    Tbl.Cell(1, 2).Range.Text = "111"
    Tbl.Cell(2, 1).Range.Text = "BBB"
    Tbl.Cell(2, 2).Range.Text = "222"
    Tbl.Cell(3, 1).Range.Text = "CCC"
    Tbl.Cell(3, 2).Range.Text = "333"
    Tbl.Cell(4, 1).Range.Text = "DDD"
    Tbl.Cell(4, 2).Range.Text = "444"

    With objApp
    .Selection.Font.Bold = True
    .Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
    .Selection.TypeText Text:=vbCrLf
    .Selection.TypeText Text:="Thank you!"
    End With


    objApp.ActiveDocument.SaveAs FileName:="c:test1.doc"
    objApp.ActiveDocument.Close False
    objApp.Quit False
    Set objApp = Nothing
    End Sub
    [/VBA]

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hey Tommy,

    I'm glad you and geekgirlau came along. How's the sunburn
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I agree with qeekgirlau. I usually make a variable to hold the document and use that var to work on the doc.

    I also agree with lucas, the dim statements need to be inside the sub/functions.

    The following are a few suggestions, please do not take it as criticism.

    1.) If you are going to make a global var place it in a module and use the public keyword, never make a public var in a form - this will load the form every time the var is accessed. 2.) Break the code into smaller subs/functions. This will help later for code reuse. ex Have a sub named OpenWordDoc to start word and open an existing doc/ open a new doc. One to create tables returning the number rows and columns and another to fill the table.

    3.) Take all the code out of the form_Load. This should be to inialize vars/setup for work. Move the code to a command button click. This way you can test over and over without haveing to restart the app.

    4.) Add objApp.Visible = True This will allow you to see what is going on while you work, enabling you to stop and retry when it doesn't work or something happens.

    I am not trying to tell you what to do just making a few suggestions to help out.

    Hey lucas sunburn is fine and now I am molting (peeling). Back to detailing built-up and angle bracing.

  8. #8
    This is what I want from this site.
    Every idea/suggestion/advice is what I am expecting.
    Salute and thanks to ALL!
    I would test it and report whether I miss.

  9. #9
    I have question(s) regarding the global declaration suggestion.
    Regarding
    Dim Tbl As Table
    Dim objApp As Word.Application
    which I declare outside the Form_Load().
    I need the "objApp" for the "How are you?." - Sub/Function 1
    I need the "Tb1" for the table. - Sub/Function 2
    I need the "objApp" for the "Thank you!..." - Sub/Function 3
    How could I accomplish the above for it/them ?
    Any idea/suggestion/advice is/are WELCOME!
    Thanks!

  10. #10
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Mr Doubtfire, this is how I would do it. This does not mean it is the best, or preferred, it is just my way .

    Something that needs work is to move the curser to a new location, not having the tme now to work on it a suggestion is to look at the collapse move to end methods.

    In a module

    [VBA]
    Option Explicit
    Private Sub Form_Load()
    End Sub
    Option Explicit
    Public Tbl As Table
    Public objApp As Word.Application
    Public WrdDoc As Word.Document
    '**********************************************************
    ' StartWrd (SUB)
    '
    ' PARAMETERS:
    ' (In/Out) - iDoc - String - value passed must have a valid
    ' location and full doc name
    ' "C:\test\test1.doc"
    '
    ' DESCRIPTION:
    '
    '**********************************************************
    Public Sub StartWrd(iDoc As String)
    'iDoc must have the full validated path to the doc with
    'the full doc name
    On Error Resume Next
    Set objApp = New Word.Application
    DoEvents '<- I add this to give Word time to work and
    'finish opening
    Set WrdDoc = objApp.Documents.Open(iDoc)
    ' check for error and display if there is one inform
    'user what happened
    If Err.Number <> 0 Then
    MsgBox Err.Description
    Err.Clear
    Else
    objApp.Visible = True
    End If
    ' turn off error checking - don't want it to show up
    'someplace else
    On Error GoTo 0
    End Sub

    '*********************************************************
    ' KillWrd (SUB)
    '
    ' PARAMETERS:
    ' (In/Out) - iSvDoc - String - value passed must have a
    ' valid location and full doc name
    ' "C:\test\test1.doc"
    '
    ' DESCRIPTION: Used to save a document and close word
    '
    '*********************************************************
    Public Sub KillWrd(iSvDoc As String)
    'iSvDoc must have the full validated path to the doc
    'with the full doc name
    WrdDoc.SaveAs iSvDoc
    WrdDoc.Close False
    Set WrdDoc = Nothing '<- be nice, release variable
    objApp.Quit False
    Set objApp = Nothing '<- be nice, release variable
    End Sub

    '*********************************************************
    ' AddText (SUB)
    '
    ' PARAMETERS:
    ' (In/Out) - iTextToAdd - String - string of text to be
    ' added at current location of the curser
    '
    ' DESCRIPTION: NOTE the selection must be set in advance
    '
    '*********************************************************
    Public Sub AddText(iTextToAdd As String)
    With objApp
    .Selection.Font.Bold = True
    .Selection.ParagraphFormat.Alignment = _
    wdAlignParagraphCenter
    .Selection.TypeText Text:=iTextToAdd
    .Selection.TypeText Text:=vbCrLf
    .Selection.ParagraphFormat.Alignment = _
    wdAlignParagraphLeft
    End With
    End Sub

    '*********************************************************
    ' GenTable (SUB)
    '
    ' PARAMETERS:
    ' (In/Out) - iColumns - Long -
    ' (In/Out) - iRows - Long -
    '
    ' DESCRIPTION:
    '
    '*********************************************************
    Public Sub GenTable(iColumns As Long, iRows As Long)
    Dim EndOfCellMarker As String
    EndOfCellMarker = Chr(13) & Chr(9)
    Set Tbl = WrdDoc.Tables.Add(Range:=Selection.Range, _
    NumRows:=iRows, NumColumns:=iColumns)
    Tbl.Range.Font.Bold = True
    Tbl.Columns(1).Width = 20
    'your way

    Tbl.Cell(1, 1).Range.Text = "AAA"
    Tbl.Cell(1, 2).Range.Text = "111"
    Tbl.Cell(2, 1).Range.Text = "BBB"
    Tbl.Cell(2, 2).Range.Text = "222"
    Tbl.Cell(3, 1).Range.Text = "CCC"
    Tbl.Cell(3, 2).Range.Text = "333"
    Tbl.Cell(4, 1).Range.Text = "DDD"
    Tbl.Cell(4, 2).Range.Text = "444"
    End Sub



    [/VBA]

    In your form

    [VBA]
    Private Sub Command1_Click()
    StartWrd "C:\test1.doc"
    AddText "How are you?"
    GenTable 2, 4
    AddText "Thank you!"
    KillWrd "C:\test.doc"
    End Sub

    [/VBA]

    Happy coding

  11. #11

    Very clear coding with explanation.
    I would try it later.
    Thanks for the first lesson of VB.
    I am waiting for the second.................

  12. #12
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    My two cents.

    Tommy is correct that it is much better to have separate procedures. Having chunks, especially if commented (as his is) makes it much easier to debug things.

    I would use more With statements, and include inserted text as one piece of code, rather than multiple. For example:
    [vba]With objApp
    .Selection.Font.Bold = True
    .Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Selection.TypeText Text:=iTextToAdd
    .Selection.TypeText Text:=vbCrLf
    .Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
    End With[/vba]
    could be replaced by:
    [vba]Public Sub AddText(iTextToAdd As String)
    With objApp.Selection
    .Font.Bold = True
    .ParagraphFormat.Alignment = wdAlignParagraphCenter
    .TypeText Text:=iTextToAdd & vbcrlf
    .ParagraphFormat.Alignment = wdAlignParagraphLeft
    End With[/vba]

    Tommy's code for GenTable declares and sets string variable EndOfCellMarker. This variable is never used in the code. I also wonder if it is needed, as every cell in fact has a endofcell marker.

  13. #13
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Gerry the EndOfCellMarker is a string that I ws going to show an alternate way to insert text into the table, instead of directly for each cell. I didn't have time to finish it so I took out part of it (my bad). I will post the code when I have time to debug.

    LOL your replacement code is good! Slipped by me, sorry, I had planned on using the WrdDoc object, I aslo forgot to Set Tbl = Nothing.

    I started with Word95 and VB5, so I get confused quite a bit cause MY code has a lot of documentation for problems I had with development, since it was a problem in the past I just don't go there, some may have been fixed in newer realeases.

  14. #14
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Ah...makes sense to insert text as a string. However:

    1. you set EndOfCellmarker quite specifically as Chr(13) and Chr(9), not as inserted text. So I am not sure what you were trying to with the textual content to go into a cell.

    1. The Chr(13) & Chr(9) is incorrect. Go to an empty cell (ie. no text in it) and select it. The only thing that will be selected is the endof cell marker. This essentially a special type of paragraph mark. I have got into a large discussion regarding this mark elsewhere. I still insist that, within the Word Object model, this IS a paragraph mark. ALL cells in a table count as individual paragraphs in Paragraphs.Count. With an empty cell, try running:
    [vba]MsgBox Asc(Left(Selection.Text, 1)) & " " & Asc(Right(Selection.Text, 1))[/vba]

    This returns a Chr(13) and a Chr(7) - not Chr(9). The endofcell marker is a unique TWO character object that is read in the character count of a document as ONE character. The Chr(7) - or "bell" - is the "ding" sound of a typewriter when it reaches the end of its carriage.

  15. #15
    After inserting "444" (last row data of table), do I need to move the cursor to the next line before "AddText" for "Thank you"?
    Thanks.

  16. #16
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Gerry I picked up on that after the post, thanks, I remember it was in that range of numbers somewhere .
    My idea was to make a string with the chr(13) & chr(7) to tell word that this is in 1 cell the next cell so forth and so on. After all when you say

    [VBA]
    Dim sData as String
    sData = ActiveDocument.Tabels(1).Range.Text
    [/VBA]

    sData contains all the text with the chr(13) & chr(7) for each cell and once again for each end of row . So I was just trying to reverse the process. It looks like I can't get it to work right now

    Mr Doubtfire the below sub is modified from the original post to move the curser to the end of the table.

    [VBA]
    '*********************************************************
    ' GenTable (SUB)
    '
    ' PARAMETERS:
    ' (In/Out) - iColumns - Long -
    ' (In/Out) - iRows - Long -
    '
    ' DESCRIPTION: this sub will generate a table based on the
    ' number of rows and columns fill the first 2 columns
    ' with data move the curser to the end of the table
    ' and move 1 more line.
    '
    '*********************************************************
    Public Sub GenTable(iColumns As Long, iRows As Long)
    Set Tbl = WrdDoc.Tables.Add(Range:=objApp.Selection.Range, _
    NumRows:=iRows, NumColumns:=iColumns)
    Tbl.Range.Font.Bold = True
    Tbl.Columns(1).Width = 20
    Tbl.Cell(1, 1).Range.Text = "AAA"
    Tbl.Cell(1, 2).Range.Text = "111"
    Tbl.Cell(2, 1).Range.Text = "BBB"
    Tbl.Cell(2, 2).Range.Text = "222"
    Tbl.Cell(3, 1).Range.Text = "CCC"
    Tbl.Cell(3, 2).Range.Text = "333"
    Tbl.Cell(4, 1).Range.Text = "DDD"
    Tbl.Cell(4, 2).Range.Text = "444"
    Set Tbl = Nothing '<- be nice, release variable
    objApp.Selection.MoveEnd Unit:=wdTable, Count:=1 '<-
    'move to end of table
    objApp.Selection.MoveDown Unit:=wdLine, Count:=1, _
    Extend:=wdMove '<- move foward 1 line
    End Sub

    [/VBA]

  17. #17
    I have a question first before reporting my problem.
    What is the difference between
    Set objApp = New Word.Application
    and
    Set objApp = createobject("Word.Application ")
    ?

    I am running under XP platform but the folder(s) involved have the permissions (Full control) to Everyone and logged under Administrator. (therefore it is NOT a permission issue and please note this setting is just for testing ONLY)

    I got the error message "This file could not be found...............(C:\test.doc)"
    I ran the following code.
    [vba]
    Option Explicit
    Public Tbl As Table
    Public objApp As Word.Application
    Public WrdDoc As Word.Document
    '************************************************************************** *****
    ' StartWrd (SUB)
    '
    ' PARAMETERS:
    ' (In/Out) - iDoc - String - value passed must have a valid location and full doc name
    ' "C:\test\test1.doc"
    '
    ' DESCRIPTION:
    '
    '************************************************************************** *****


    Private Sub Form_Load()
    StartWrd "C:\test.doc"
    AddText "How are you?"
    GenTable 2, 4
    AddText "Thank you!"
    KillWrd "C:\test.doc"


    End Sub
    Public Sub StartWrd(iDoc As String)
    'iDoc must have the full validated path to the doc with the full doc name
    On Error Resume Next
    Set objApp = New Word.Application
    DoEvents '<- I add this to give Word time to work and finish opening
    Set WrdDoc = objApp.Documents.Open(iDoc)
    ' check for error and display if there is one inform user what happened
    If Err.Number <> 0 Then
    MsgBox Err.Description
    Err.Clear
    Else
    objApp.Visible = True
    End If
    ' turn off error checking - don't want it to show up someplace else
    On Error GoTo 0
    End Sub

    '************************************************************************** *****
    ' KillWrd (SUB)
    '
    ' PARAMETERS:
    ' (In/Out) - iSvDoc - String - value passed must have a valid location and full doc name
    ' "C:\test\test1.doc"
    '
    ' DESCRIPTION: Used to save a document and close word
    '
    '************************************************************************** *****
    Public Sub KillWrd(iSvDoc As String)
    'iSvDoc must have the full validated path to the doc with the full doc name
    WrdDoc.SaveAs iSvDoc
    WrdDoc.Close False
    Set WrdDoc = Nothing '<- be nice, release variable
    objApp.Quit False
    Set objApp = Nothing '<- be nice, release variable
    End Sub

    '************************************************************************** *****
    ' AddText (SUB)
    '
    ' PARAMETERS:
    ' (In/Out) - iTextToAdd - String - string of text to be added at current location of the curser
    '
    ' DESCRIPTION: NOTE the selection must be set in advance
    '
    '************************************************************************** *****
    Public Sub AddText(iTextToAdd As String)
    With objApp
    .Selection.Font.Bold = True
    .Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Selection.TypeText Text:=iTextToAdd
    .Selection.TypeText Text:=vbCrLf
    .Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
    End With
    End Sub

    '************************************************************************** *****
    ' GenTable (SUB)
    '
    ' PARAMETERS:
    ' (In/Out) - iColumns - Long -
    ' (In/Out) - iRows - Long -
    '
    ' DESCRIPTION: this sub will generate a table based on the number of rows and columns
    ' fill the first 2 columns with data move the curser to the end of the table and move 1 more line.
    '
    '************************************************************************** *****
    Public Sub GenTable(iColumns As Long, iRows As Long)
    Set Tbl = WrdDoc.Tables.Add(Range:=objApp.Selection.Range, NumRows:=iRows, NumColumns:=iColumns)
    Tbl.Range.Font.Bold = True
    Tbl.Columns(1).Width = 20
    Tbl.Cell(1, 1).Range.Text = "AAA"
    Tbl.Cell(1, 2).Range.Text = "111"
    Tbl.Cell(2, 1).Range.Text = "BBB"
    Tbl.Cell(2, 2).Range.Text = "222"
    Tbl.Cell(3, 1).Range.Text = "CCC"
    Tbl.Cell(3, 2).Range.Text = "333"
    Tbl.Cell(4, 1).Range.Text = "DDD"
    Tbl.Cell(4, 2).Range.Text = "444"
    Set Tbl = Nothing '<- be nice, release variable
    objApp.Selection.MoveEnd Unit:=wdTable, Count:=1 '<- move to end of table
    objApp.Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdMove '<- move foward 1 line
    End Sub

    [/vba]

    Thanks and please advice.

  18. #18
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    I haven't looked at your code, but I thought I'd answer your first question. There is a difference between the two methods, but they both essentially create a new instance of Word. For what you're trying to do here, I wouldn't worry about the difference. If you're still curious, this article at the MSDN might be helpful: http://msdn.microsoft.com/library/de...components.asp

    Edit: On second thought, I was too brief. It might be better to stick with the CreateObject since that works in all circumstances (early or late bound objects) while New doesn't (early bound objects only). In other words, you'd have to have a reference to the library in your project to use New (that's already here by default since you're using the Word library), but you wouldn't have to worry about the reference if you used CreateObject (good when working from another application). Another advantage of CreateObject is your code would work with different versions of Word.

    I'm not sure how understandable that explanation was. If you want to discuss this in more detail, we should start a new thread for it, because I think it will be of interest to others as well.

  19. #19
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Tommy, I am not sure what you mean by "Data contains all the text with the chr(13) & chr(7) for each cell and once again for each end of row" .

    Please explain your statement "one again". The fact is:

    sData = ActiveDocument.Tabels(1).Range.Text means precisiely this:

    sData = all text between the Long Integer calculated to be the CURRENT Range.Start of the table, and the Long Integer as the Range.End of the table. Period. There is NO determination of the number of paragraph associated with the text assigned by the instruction. There is no review nor calculation of endofcell, OR endofRow, The VALUE is all text between 41,234 and 41,966- for example. The Range.Start has a specific calculated Long, as does the .End. SData = all characters between those numbers. It means no more, but no less.

  20. #20
    I have some questions here as followed:

    1. My table has Font '10' and when I set column width setting (like 40 characters for each one)
    this DOES NOT work Tbl.Columns(1).Width = 20
    instead I have to do Tbl.Columns(1).Width = 300
    Is it in pixels of proportional font size !?
    2. How I could get rid of the table GRID lines inside the Word document ?
    3. How I could test the existing of an instance of MS-Word, if YES how I could get
    rid of it and make sure it is always a fresh start?
    4. I have tried to put a loop for a mulitple running to get several Word documents
    and found out the first time was successful, and got stuck the second time on the
    line with "Set Tbl=......", although there is "Set Tbl = nothing".
    Please advice.
    THANKS!

Posting Permissions

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