Consulting

Results 1 to 6 of 6

Thread: Solved: how do do i get my string to appear on the word document

  1. #1
    VBAX Regular k13r4n's Avatar
    Joined
    Nov 2008
    Posts
    31
    Location

    Question Solved: how do do i get my string to appear on the word document

    hi everyone

    i have some experience using VB Script in web development but im completely new to VB for applications, and ive got stuck on what is probably a really daft thing.

    I have a simple loop that grabs some info out of a table in excel and arranges it into a text string to use as a script for AutoCAD. That all works fine, the problem is i need the string to goto word so that it can be saved as a plain text file.

    Ive managed to work out how to open a new word document by reading through the forums here but i cant work out how to put the string onto the page!

    Most examples talk about opening templates and using bookmarks but i dont want to do any of that i just want a string of text dumped on the page.

    ive been searching the forums and the net for 2 days now and cant find out how, if anyone can help or point me to an artical i can read that would be great.

    here is a snippit
    Ive opened the new document
    [vba]Set ObjWord = CreateObject("Word.application")
    ObjWord.Visible = True
    ObjWord.documents.Add[/vba]

    and i have my string
    [vba]
    "rectang " & xStart & "," & yStart & " @" & pLength & "," & pWidth
    [/vba]

    Whats the bit of code i need to put infront of that string to make it display on the word document? I can get it to output to a cell in excel just fine but i cant get it onto the new word document

    Cheers

    Kieran

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You can write to a text file in Excel, no need for Word.

    [vba]

    Dim FileNumber

    FileNumber = FreeFile
    Open "TEST" For Output As #FileNumber
    Write #FileNumber, "This is a sample."
    Close #FileNumber
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Or better,

    [vba]

    Dim FileNumber
    FileNumber = FreeFile
    Open "TESTxxxxx.txt" For Output As #FileNumber
    Print #FileNumber, "This is a sample."
    Print #FileNumber, "This is another sample."
    Close #FileNumber
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Regular k13r4n's Avatar
    Joined
    Nov 2008
    Posts
    31
    Location
    Quote Originally Posted by xld
    Or better,

    [vba]

    Dim FileNumber
    FileNumber = FreeFile
    Open "TESTxxxxx.txt" For Output As #FileNumber
    Print #FileNumber, "This is a sample."
    Print #FileNumber, "This is another sample."
    Close #FileNumber
    [/vba]
    Thanks xld
    Could you just explain FileNumber = FreeFile bit? and why is there a # infront of FileNumber?

    cheers

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That is just the syntax. FreeFile is a VBA function that returns the next file number slot available. This is passed to a vraibale which is used when open ing and printing the text file. It is probably making life simple for the compiler.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Regular k13r4n's Avatar
    Joined
    Nov 2008
    Posts
    31
    Location
    Thanks xld, got it all sorted

Posting Permissions

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