Solved

Saving a document created with vb in word

Posted on 2000-02-21
8
177 Views
Last Modified: 2010-05-02
i have externally created a word document from my vb application, and it has opened word, added a document (documents.add) and written stuff to the selection.

how do you save the document without a prompt as a certain filename... i dont want it to be called "document 1.txt" or anything like that. OR... if i MUST have a prompt, (as in, if i just go.. documents.save true, true) how do i allow it to overwrite files already there?

thanx
0
Comment
Question by:Sesh
  • 4
  • 2
  • 2
8 Comments
 

Expert Comment

by:amuru
ID: 2544491
Do u want to save the word.doc without any prompt ???
0
 

Author Comment

by:Sesh
ID: 2544493
yes... i want to save it as a specific filename without prompting

also, how do you kill off the application when you are finished with it... is there a Word.Application.Close?
0
 

Author Comment

by:Sesh
ID: 2544498
yes... i want to save it as a specific filename without prompting

also, how do you kill off the application when you are finished with it... is there a Word.Application.Close?
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 100 total points
ID: 2544525
This code saves without prompting the user and quit.

Private Sub Command2_Click()
Dim objWord As Word.Application

    Set objWord = New Word.Application
   
    With objWord
        .Visible = True
        .Documents.Add
        .ActiveDocument.Select
        .Selection.InsertAfter "Hello"
        .ActiveDocument.SaveAs App.Path & "\t.doc"
        .Quit False
    End With
    Set objWord = Nothing
End Sub
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Expert Comment

by:amuru
ID: 2544577
wdPromptToSaveChanges, or wdSaveChanges

Change the below Prompt to save without prompt :

On Error GoTo errorHandler
ActiveDocument.Close SaveChanges:=wdPromptToSaveChanges, OriginalFormat:=wdPromptUser
errorHandler:
If Err = 4198 Then MsgBox "Document was not closed"

to kill the Application use :
goWord.quit

set goWord = Nothing

Above is just the command to close opened word.  Add some coding to check activedocument.
0
 

Author Comment

by:Sesh
ID: 2553543
thanx a lot for that... its exactly what i was looking for

just one other thing, though... how do you insert tabs, create tabstops and insert those horizontal lines that appear when you type

---------

on a new line????

help in this would be really great.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 2555144
I never played with tabs by automation so can't help on this one.

About your horizontal lines: which lines???
0
 

Author Comment

by:Sesh
ID: 2563899
dont worry.. i figured it out. :)

i was referring to the wdBorderTop..
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now