+ Reply to Thread
Results 1 to 2 of 2

Copy a word from a doc to an excel cell - vba

  1. #1
    Registered User
    Join Date
    01-14-2019
    Location
    Szeged
    MS-Off Ver
    MS Office365
    Posts
    1

    Copy a word from a doc to an excel cell - vba

    Hi Guys,

    My problem is the following. The following code finds the text what I want, but I don't know how to copy it in excel cell.

    Private Sub CommandButton1_Click() 'Teszt_2_1

    Dim ws As Worksheet, msWord As Object

    Set ws = ActiveSheet
    Set msWord = CreateObject("Word.Application")

    Dim a As Variant

    For a = 2 To 3

    With msWord
    .Visible = True

    .Documents.Open "C:\Users\mahlj01\Desktop\Egy嶵\Dokumentumkezelő\Excelek_v2\" & Range("A" & a) & ".doc"

    .Activate

    Dim b As Variant
    For b = 2 To 2

    With .ActiveDocument.Content.Find
    .ClearFormatting

    .Text = Worksheets("Teszt_2").Cells(b, 2).Value
    With .Replacement
    .ClearFormatting
    .Font.Bold = True
    .Font.Color = 65280 '12611584
    .Text = Worksheets("Teszt_2").Cells(b, 2).Value
    End With

    .Replacement.Text = Worksheets("Teszt_2").Cells(b, 2).Value
    .Forward = True
    .Wrap = 1 'wdFindContinue (WdFindWrap Enumeration)
    .Format = True
    .MatchCase = False
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=2 'wdReplaceAll (WdReplace Enumeration)

    'While .Excute

    If .Found = True Then
    .Copy

    Worksheets("Teszt_2").Cells(a, 3) =

    End If

    End With

    Next b

    .ActiveDocument.Save
    .ActiveDocument.Close _
    SaveChanges:=wdSaveChanges

    End With

    Next a

    End Sub

    Any idea?

  2. #2
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    Pro 2019
    Posts
    14,291

    Re: Copy a word from a doc to an excel cell - vba

    Welcome to the Forum Janos_Mahl!

    I moved your thread from Hello..Introduce Yourself because people do not monitor that subforum for questions.

    Since you are new, I was going to edit your post to add code tags, but there is a hiccup on the site and I can't edit your post. Please add tags around your code. There are two ways to add code tags. One is to select the code part of the text so it is highlighted, then press the "#" button in the edit controls. The other is to simply type in the tags:

    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code]


    We have a rule requiring code tags, so please make this change before the thread continues.
    Jeff

    STOP PRESS: Forum Rules Updated September 2018! Please read them here.

    Making the world a better place one fret at a time | | |會 |會 |會 |會 | |:| | |會 |會

    If someone helped you please click on the star icon at the bottom of their post
    If your problem is solved please go to Thread Tools and select Mark This Thread Solved
    Don't attach a screenshot--just attach your Excel file! It's easier and will let us experiment with your data, formulas, and code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1