Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by Tocogroup
at 2024-11-30 05:03:35
Point:500 Replies:11 POST_ID:828848USER_ID:11762
Topic:
Microsoft Excel Spreadsheet Software;;Microsoft Word
Hi All,
I have an Excel 2010 VBA application in which I open a Word document and save it with a different filename.
When I close the Word document the 'copied' version is still open. It might be obvious but how do I close this 'Doc' file within my VBA code ?
The code looks like this....
Dim WordApp As Object
Dim WordDoc As Object
WordDoc.Save
WordApp.Documents.Add WordDoc.FullName
WordDoc.SaveAs strDocumentName
MsgBox "Your Word document has been saved as " & strDocumentName, vbInformation
WordDoc.Close
I have an Excel 2010 VBA application in which I open a Word document and save it with a different filename.
When I close the Word document the 'copied' version is still open. It might be obvious but how do I close this 'Doc' file within my VBA code ?
The code looks like this....
Dim WordApp As Object
Dim WordDoc As Object
WordDoc.Save
WordApp.Documents.Add WordDoc.FullName
WordDoc.SaveAs strDocumentName
MsgBox "Your Word document has been saved as " & strDocumentName, vbInformation
WordDoc.Close
Expert: duncanb7 replied at 2024-11-30 06:52:15
Thanks for your pt and Graham's reminder is a key solution in this thread
have a nice day
Duncan
have a nice day
Duncan
Author: Tocogroup replied at 2024-11-30 06:49:39
Hi Duncan and Graham,
Thank you both very much for your suggestions regarding wdDoNotSaveChanges.
I'm splitting the points on this one as I combined your codes and got there in the end as well as having understood how it works. It's a big read to close two documents !!
Much appreciated
Toco
Thank you both very much for your suggestions regarding wdDoNotSaveChanges.
I'm splitting the points on this one as I combined your codes and got there in the end as well as having understood how it works. It's a big read to close two documents !!
Much appreciated
Toco
Accepted Solution
Expert: duncanb7 replied at 2024-11-30 06:21:52
250 points EXCELLENT
GrahamSkan is correct,
Tocogroup,Please read it that might help you about late or early binding.
http://www.globaliconnect.com/excel/index.php?option=com_content&view=article&id=169:automate-microsoft-word-from-excel-using-vba&catid=79&Itemid=475
If not, I have no more comment in this thread.
Have a nice day
Duncan
Tocogroup,Please read it that might help you about late or early binding.
http://www.globaliconnect.com/excel/index.php?option=com_content&view=article&id=169:automate-microsoft-word-from-excel-using-vba&catid=79&Itemid=475
If not, I have no more comment in this thread.
Have a nice day
Duncan
Assisted Solution
Expert: GrahamSkan replied at 2024-11-30 06:09:44
250 points EXCELLENT
Can you say what happens with my suggestion, please?
wdDoNotSaveChanges is a constant defined in the Microsoft Word object library, but you are using late binding
wdDoNotSaveChanges is a constant defined in the Microsoft Word object library, but you are using late binding
Author: Tocogroup replied at 2024-11-30 06:04:06
Neither of your suggestions worked.
The second one didn't recognise the variable wdDoNotSaveChanges
The second one didn't recognise the variable wdDoNotSaveChanges
Expert: duncanb7 replied at 2024-11-30 05:51:06
if you just want to close all documents not application, you can try this
'--Loop Through open documentsWith WordAppDo Until .Documents.Count = 0'--Close with save.Documents(1).Close SaveChanges:=wdSaveChanges'--Close no save'--.Documents(1).Close SaveChanges:=wdDoNotSaveChangesLoopEnd With 1:2:3:4:5:6:7:8:9:10:11:12:
Duncan
Expert: GrahamSkan replied at 2024-11-30 05:46:41
Set the document object when you open it in the first place, otherwise there is confusion about which document is being worked on.
Dim WordApp As Object 'Word.Application Dim WordDoc As Object 'Word.Docunent '... Set WordDoc = WordApp.Documents.Open("C:MyFolderMyFile.doc") WordDoc.SaveAs strDocumentName MsgBox "Your Word document has been saved as " & strDocumentName, vbInformation WordDoc.Close 1:2:3:4:5:6:7:8:9:
Expert: duncanb7 replied at 2024-11-30 05:42:38
Probably, you want to close word application not word document since
you care the copied one is still open
if so, just try this
WordApp.Quit
set WordApp = Nothing
you care the copied one is still open
if so, just try this
WordApp.Quit
set WordApp = Nothing
Expert: Saqib Husain, Syed replied at 2024-11-30 05:34:30
Try
wordapp.activedocument.close
wordapp.activedocument.close
Author: Tocogroup replied at 2024-11-30 05:18:55
Fraid it didn't. I got an Error 438 - Object doesn't support this property or method
Expert: duncanb7 replied at 2024-11-30 05:06:05
Is it WordDoc.quit ? it might work
Duncan
Duncan