Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Using Excel VBA to control Word (open document)

Using Office2003 on WinXP

I have excel VBA code that does a bunch of stuff in Excel, and now needs to
open up an existing Word document, delete (or clear) some bookmarks
determined by the XL VBA code, then save the Word document under a new name.

#1
Right now, when it gets to the code to open the file, Excel hangs and (if I
close all the other windows) I see a dialog box that says "File in use;
[document] is locked for editing by [me], with options to open a read-only
copy, create a local copy, or wait for notification.

Read-only would be fine because I'll need to save under a different name
anyway- can anyone take a look at the code below and offer a tweak to open
the file without the warning?

#2
When I manually select to open the file as read only, either deleting the
bookmark or setting the text to "" in my loop, it loops several times then
gives an error- I suspect that deleting (and possibly emptying) the
bookmarks resets the bookmark count which means that I'm not deleting all
the ones I want, and I'm probably deleting the wrong ones along the way as
the earlier bookmaks are deleted.

Without pasting my array to a worksheet, what would be the best way to sort
the array (which includes some blank values) so I can delete the bookmarks
in decending order?

Many thanks,
Keith

Sub MakeGuideA()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
'wrdApp.Visible = True

Set wrdDoc = wrdApp.Documents.Open(CurrentPath & "\Interview_GuideA" &
".doc")

'word operations
With wrdDoc
For deleteComp = 1 To 18
If WordArray(deleteComp) < "" Then
wrdDoc.Bookmarks(deleteComp).Range.Text = "" ' or
Range.Delete
End If
Next
wrdDoc.SaveAs (CurrentPath & ApplicantName & ".doc")
.Close ' close the document
End With

wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
ActiveWorkbook.Saved = True
End Sub




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Using Excel VBA to control Word (open document)

Keith,
The 3rd argument of Word's open method is Read-Only. Try setting that to
True.

Or Word has the DisplayAlerts property the same as Excel, which can take one
of the values of the WdAlertLevel enum; I guess you need wdAlertsNone, which
has a value of 0, i.e. False.

NickHK

"Keith" wrote in message
...
Using Office2003 on WinXP

I have excel VBA code that does a bunch of stuff in Excel, and now needs

to
open up an existing Word document, delete (or clear) some bookmarks
determined by the XL VBA code, then save the Word document under a new

name.

#1
Right now, when it gets to the code to open the file, Excel hangs and (if

I
close all the other windows) I see a dialog box that says "File in use;
[document] is locked for editing by [me], with options to open a read-only
copy, create a local copy, or wait for notification.

Read-only would be fine because I'll need to save under a different name
anyway- can anyone take a look at the code below and offer a tweak to open
the file without the warning?

#2
When I manually select to open the file as read only, either deleting the
bookmark or setting the text to "" in my loop, it loops several times then
gives an error- I suspect that deleting (and possibly emptying) the
bookmarks resets the bookmark count which means that I'm not deleting all
the ones I want, and I'm probably deleting the wrong ones along the way as
the earlier bookmaks are deleted.

Without pasting my array to a worksheet, what would be the best way to

sort
the array (which includes some blank values) so I can delete the bookmarks
in decending order?

Many thanks,
Keith

Sub MakeGuideA()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
'wrdApp.Visible = True

Set wrdDoc = wrdApp.Documents.Open(CurrentPath & "\Interview_GuideA" &
".doc")

'word operations
With wrdDoc
For deleteComp = 1 To 18
If WordArray(deleteComp) < "" Then
wrdDoc.Bookmarks(deleteComp).Range.Text = "" ' or
Range.Delete
End If
Next
wrdDoc.SaveAs (CurrentPath & ApplicantName & ".doc")
.Close ' close the document
End With

wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
ActiveWorkbook.Saved = True
End Sub






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel trying to open word document tina Excel Discussion (Misc queries) 2 April 19th 07 02:16 PM
Open A Word Document from Excel roadkill Excel Programming 4 November 4th 05 10:15 PM
open word document in excel spaceslime Excel Discussion (Misc queries) 1 August 13th 05 03:15 PM
what happens if I open an excel document in word? Emily Excel Discussion (Misc queries) 3 April 2nd 05 10:49 AM
Open a word document in excel Michael[_29_] Excel Programming 1 March 2nd 04 09:58 PM


All times are GMT +1. The time now is 10:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"