Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do u create a word doc (as opposed to opening)? 4

Status
Not open for further replies.

mijulie

Programmer
Jun 21, 2001
36
0
0
IE
If this is the code for opening an existing doc, anyone know what command i need to create a doc?

Set Word = CreateObject("Word.Application")
Word.Visible = TRUE
Word.Documents.Open("C:\My Documents\myfile.doc")
 
Hello,
Word.Documents.Add
creates a new empty word document.
D.
 
That's great but can i trouble u for some more info? I need to write to a word doc. I know how to write to a textfile using the filetxt.WriteLine method. Can u tell me what the format for writing to a word doc is please. I would really appreciate any help!
Mijulie
 
I would suggest to you to go into Word, select Tools --> Macros --> Record New Macro

And just go to town typing --

Once you're finished, then press the Stop button and open up the VBA editor to look at the code you created. That's the best trick I know of to find out how to interface with MSOffice Apps programatically.

:)
Paul Prewett
penny.gif
penny.gif
 
Hello,
Take a look on your computer in
C:\Program Files\Microsoft Office\Office\1033\VBAWRD9.CHM

CHM files are compiled HTML Help files.
All started with VBA are for Visial Basic for Applications.
They are installed when you installed MS Office.

Success!
D.
 
I've found the solution, using the add method. Only thing is every time i write to it, it keeps going on the same line. I want to be able to move on to a new line when i have to. Does anyone know what the code for this might be,
Selection.InsertLine or something?
 
Hello,
Well ,
TypeParagraph or Chr(11) - Line feed


Selection.TypeText Text:="dffdfd"
Selection.TypeParagraph
Selection.TypeText Text:="dkfk" & Chr(11) & "fdk"

D.
 
The TypeParagraph works like a dream, thanks for that. Would you know how to create a table in Word document?
 
Hello,
Follow the link9 suggestion - using macros in Word is great - you can view and edit macros.

<script language=&quot;VBScript&quot;>
Dim objWord
Set objWord=CreateObject(&quot;Word.Application&quot;)
Set oDoc = objWord.Documents.Add

'Tables.Add(Range, NumRows, NumColumns, DefaultTableBehavior, AutoFitBehavior)

Set oTable = oDoc.Tables.Add(oDoc.Range(0,0), 3, 4)
iCount = 1
For Each oCell In oTable.Range.Cells
oCell.Range.InsertAfter &quot;Cell &quot; & iCount
iCount = iCount + 1
Next
oTable.AutoFormat Format=wdTableFormatColorful2, ApplyBorders=True, ApplyFont=True, ApplyColor=True
objWord.Visible = true

'objWord.Quit
Set objWord=Nothing
</script>
 
Okay, that seems pretty straight forward but how do I name and pass variables in as individual cell values. Is this very difficult, I can't seem to get it working myself. Any help would be appreciated!
Thanks,
Mijulie
 
Can anybody help me with the position of the table on the doc? It wont let me make the range anything higher than 35,35. It gives me an error if i inrease it saying &quot;value out of range&quot;. How can i put it lower on the page so I can put a heading and some lines of writing above it? objWord.Selection.TypeParagraph has no affect at all!!! Please help, I fear i may lose my marbles!!!!
 
U cannot use more then 35 cols or lines cuz this is probably the larger table in Word... ________

George
 
Is there a smaller table i could create that would allow me to do what i need??
 
Use like dianal says
Tables.Add(Range, 20'NumRows, 20'NumColumns, DefaultTableBehavior, AutoFitBehavior ________

George
 
Hello all

Can anyone tell me how to link to bookmark in a WSword document from an html link? I can open the document with the link, but it will not recognize the book mark.

This is what I have been trying

<A HREF=&quot;//hoursOfWork.doc#pay&quot;

I have tried calling the bookmark from another word doc and it works, but the html call just opens the doc, but not at the bookmark

Aceman25
 
Hey Guys,
thank you for your Ideas, but though my word starts under WinNT&word97 it is not visible...
Can anyone help me?
 
I am trying to create a Word Doc in ASP with data from a SQL Database and I am receiving an error(Could not open macro storage.).Why?
 
To Chris0001
dianal (Instructor)'s line is missing command for
Word document visible.
This is a part of VBA rather than VBScript after you
create a Object.

<script language=&quot;VBScript&quot;>
Dim objWord
Set objWord=CreateObject(&quot;Word.Application&quot;)

objWord.Visible = True ' This command for visibility

Set oDoc = objWord.Documents.Add

'Tables.Add(Range, NumRows, NumColumns, DefaultTableBehavior, AutoFitBehavior)

Set oTable = oDoc.Tables.Add(oDoc.Range(0,0), 3, 4)
iCount = 1
For Each oCell In oTable.Range.Cells
oCell.Range.InsertAfter &quot;Cell &quot; & iCount
iCount = iCount + 1
Next
oTable.AutoFormat Format=wdTableFormatColorful2, ApplyBorders=True, ApplyFont=True, ApplyColor=True
objWord.Visible = true

'objWord.Quit
Set objWord=Nothing
</script>
 
Self responce

I made a mistake above.

The last line
Set objWord=Nothing
is the reason why the Document becomes invisible.

So if you put a line
WScript.Sleep(10000)
before the line, you may see the document for 10 seconds.


 
Ive never used ASP before only JSP and its completely different so im hoping one of u can help me out here.
Im starting a project next week using ASP's to write a contract in .doc and .pdf format.
The above should help me immensely with the word doc but i cant find anything about pdf out there.
Is there some sort of library anyone knows of that i could use?

Thanks
Dek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top