Copy Word into Excel and clear Clipboard message

WaltzAir

New Member
Joined
Sep 19, 2012
Messages
33
Could not get the Word App to quit without the "Large amount of data in clipboard" dialog and Word has no way to avoid it, so sendkeys seemed the easy way out ...
Anyone know a more elegant method?

Sub Word_to_Excel()
'
Dim wApp As Word.Application, gdoc As String
'
Set wApp = CreateObject("Word.Application")
'
gdoc = Application.GetOpenFilename("Word Files (*.doc*)," & "*doc*")
wApp.Visible = True
wApp.Documents.Open (gdoc)
wApp.Selection.WholeStory
wApp.Selection.Copy
Range("A1").Activate
wApp.Documents(1).Close
wApp.Quit
AppActivate wApp
Application.SendKeys ("{ENTER}")
Set wApp = Nothing
'
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
You can use:

Code:
wapp.cutcopymode = false

But that is going to clear what ever is on the clipboard, so you would have to do your paste into excel before you closed the word app.

You might be able to put this before the close:

Code:
wapp.displayalerts = false

and then after the close put:

Code:
wapp.displayalerts = true

Hope one of those methods will work for you?
 
Upvote 0
Code:
Sub Word_to_Excel()
Set wApp = CreateObject("Word.Application")
gdoc = Application.GetOpenFilename("Word Files (*.doc*)," & "*doc*")
wApp.Visible = True
wApp.Documents.Open (gdoc)
wApp.Selection.WholeStory
wApp.Selection.Copy
Range("A1").PasteSpecial
wApp.Documents(1).Close
wApp.Quit
Set wApp = Nothing
End Sub
 
Upvote 0
Set the document contents to a range and then convert the range to a string something like...
Code:
Dim LastParaLoc As Integer, Mydata$, MyRange As Variant
Wapp.ActiveDocument.Select
LastParaLoc = Wapp.Selection.paragraphs.Count 'last paragraph(line#)
Set MyRange = Wapp.ActiveDocument.paragraphs(1).Range
    MyRange.SetRange Start:=MyRange.Start, _
        End:=Wapp.ActiveDocument.paragraphs(LastParaLoc).Range.End
MyRange.Select
Mydata = Wapp.Selection.Text
Not sure if all this is necessary. Maybe just...
Code:
wApp.WholeStory.Select
Mydata = Wapp.Selection.Text
In either way, convert the contents of the doc to a string variable will eliminate the clipboard problem. HTH. Dave
 
Upvote 0
Are you referring to my post? If so, it does recognize these:

Code:
Application.DisplayAlerts = wdAlertsNone
Application.DisplayAlerts =wdAlertsMessageBox
Hope that helps.
 
Upvote 0
I had tried the wApp.DisplayAlerts = False to no avail (Word vba did not recognize).
Since I code Excel primarily, I did not know that syntax.


Are you referring to my post? If so, it does recognize these:

Code:
Application.DisplayAlerts = wdAlertsNone
Application.DisplayAlerts =wdAlertsMessageBox
Hope that helps.
 
Upvote 0
With this being run from Excel you may have to do something like:

Code:
wapp.displayalerts = 0 'wdalertsnone
wapp.displayalerts = -2 'wdalertsmessagebox
Since excel will probably not recognize the word built-in constants.
 
Upvote 0
Must be some other problem. The Editor autocompletes the code line, including the enumerations. I tried both the hard number and the constant, but neither work -- the alert still pops up.
The sendkeys still work, though.

With this being run from Excel you may have to do something like:

Code:
wapp.displayalerts = 0 'wdalertsnone
wapp.displayalerts = -2 'wdalertsmessagebox
Since excel will probably not recognize the word built-in constants.
 
Upvote 0

Forum statistics

Threads
1,215,072
Messages
6,122,968
Members
449,095
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top