Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
excel trying to open word document | Excel Discussion (Misc queries) | |||
Open A Word Document from Excel | Excel Programming | |||
open word document in excel | Excel Discussion (Misc queries) | |||
what happens if I open an excel document in word? | Excel Discussion (Misc queries) | |||
Open a word document in excel | Excel Programming |