Paste from Word to Excel

  • Thread starter Thread starter Steve Burr
  • Start date Start date
S

Steve Burr

Hi,

I am having difficult with controlling Excel from word.

My specific problem is related to the task of:
Copy data from word to a variable
Opening excel.
Pasting the variable data to the next available cell/row

I can copy to the variable, call and open execl but cannot seem to be able
to input the data.

I have tried various solutions found on this site and am not making headway.
I am clearly missing a bit of knowledge.

Very thankful for any guidance offered.

Kind regards
 
without posting the relavent code, you probably won't get too many replies.
 
Sub Macro5()

'Find remittance to identify this process.Selection.Find.ClearFormatting

Dim v1 As String
Dim v2 As String
Dim v3 As String
Dim v4 As String

With Selection.Find
.Text = "Email:"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveDown Unit:=wdLine, Count:=2
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
v1 = Selection.Text
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.HomeKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=10
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
v2 = Selection.Text
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=13
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
v3 = Selection.Text
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=13
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
v4 = Selection.Text

Dim oXL As Excel.Application
Dim rngXL As Excel.Range


Set oXL = New Excel.Application
Set rngXL = oXL.ActiveSheet.Range("A1")

oXL.Quit
Set oXL = Nothing
End Sub

Please forforgive my limited knowledge. I am completely stuck at the point
of passing the info to excel.

As you can see, I want to copy text from various parts of the document and
then pass it to excel.

Again any advice will be greatly apprciated.

Would I better off posting to the Word discussion group?
 
Can't comment on any of the Word code, but this should work for Excel:

'************************
Dim oXL As Excel.Application
Dim rngXL As Excel.Range

Set oXL = New Excel.Application
oXL.Visible=True

Set rngXL = oXL.ActiveSheet.Range("A1")
rngXL.value = v4

'oXL.Quit 'you probably don't really want to quit here....
Set oXL = Nothing
'************************

Tim
 
Thanks Tim, that has pointed me in the right direction. Problem all but
solved now.

I appreciate your time.

Many kind regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top