|
-
Nov 2nd, 2003, 03:09 PM
#1
Thread Starter
Fanatic Member
Copy a text from a Word Document to a string? [Resolved]
How can I copy a text from a word document into a string?
I have tried, but I can only copy not paste the text into a string?
I want to copy a text from the header in the word dokument. The text I'm coping is from the 11:th cell. How can I do that?
Last edited by Pirre001; Nov 3rd, 2003 at 12:51 PM.
-
Nov 3rd, 2003, 07:03 AM
#2
Thread Starter
Fanatic Member
-
Nov 3rd, 2003, 07:06 AM
#3
it should be a simple modification, show us the code you have got at the moment...
-
Nov 3rd, 2003, 11:47 AM
#4
Thread Starter
Fanatic Member
I got this:
VB Code:
Private Sub WordCopyPaste()
Dim wo As word.Application
Dim strt As String
On Error Resume Next
Set wo = GetObject(, "Word.Application")
If Err.Number <> 0 Then
' if word isn't open, then open it
Set wo = CreateObject("Word.Application")
End If
Err.Clear
'On Error GoTo WordError
wo.Visible = False
wo.Documents.Open ("C:\TestFile.doc")
If wo.ActiveWindow.View.SplitSpecial <> wdPaneNone Then
wo.ActiveWindow.Panes(2).Close
End If
If wo.ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow.ActivePane.View.Type = wdOutlineView Then
wo.ActiveWindow.ActivePane.View.Type = wdPrintView
End If
wo.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
wo.ActiveWindow.Panes(2).Activate
wo.Selection.MoveRight Unit:=wdCell
wo.Selection.MoveRight Unit:=wdCell
wo.Selection.MoveRight Unit:=wdCell
wo.Selection.MoveRight Unit:=wdCell
wo.Selection.MoveRight Unit:=wdCell
wo.Selection.MoveRight Unit:=wdCell
wo.Selection.MoveRight Unit:=wdCell
wo.Selection.MoveRight Unit:=wdCell
wo.Selection.MoveRight Unit:=wdCell
wo.Selection.MoveRight Unit:=wdCell
wo.Selection.Copy
wo.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'Here I want to paste the copy into a string, like this:
'strt = wo.Selection.PasteAndFormat(wdPasteDefault)
'But it doesent work.
wo.ActiveDocument.Close
wo.Application.Quit
Set wo = Nothing
End Sub
-
Nov 3rd, 2003, 12:06 PM
#5
is there a particular reason for using the clipboard?
if not, this will do the trick:
VB Code:
'....
wo.Selection.MoveRight Unit:=wdCell
strt = wo.Selection.Text
wo.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
wo.ActiveDocument.Close
'...
NB: wo.Selection.Text might not work, you may need .Value or some other property.
-
Nov 3rd, 2003, 12:32 PM
#6
[list=1][*]Manually open your document in Word[*]Start the recording of a macro[*]Manually do what you want your program to do[*]Stop the macro recording[*]Edit the macro and copy the pertinant code to your program.[*]Add wo. object references to Word's code[/list=1]
-
Nov 3rd, 2003, 12:40 PM
#7
Thread Starter
Fanatic Member
si_the_geek,
I tried your example, but it doesen't work...? The string is empty?
MartinLiss,
The code I posted here is a macro I recorded. But the last bit to paste the text, which is copied, into a string doesen't work.
-
Nov 3rd, 2003, 12:50 PM
#8
Thread Starter
Fanatic Member
It works now!
I missed to remove this row:
wo.Selection.Copy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|