Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 24 of 24

Thread: VBA for Word 2010 - How to copy text between a two headings in Word

  1. #21
    VBAX Regular pk247's Avatar
    Joined
    Feb 2014
    Posts
    64
    Location
    Thank you again Paul. Your line of code works perfectly.

    The 'Application.CutCopyMode = False' lines were added when I was testing the code and I forgot to remove them - sorry for any confusion. And thanks for the tip on sheet name! The chances are high that someone down the line will try to add/edit sheets...

    And now,,, with bated breath I hope it's not too much to ask but, well, here goes... In some (not all but quite a few) of the tables there are check-boxes - more specifically, when I double-click on the square shape inside the table Word pops up a window named "Checkbox Form Field Options" - and some check-boxes are Checked and some are Not Checked = I assume this translates to True/False? The resulting transfer in the Excel cell is this symbol:  (I don't know if this is displaying correctly but it's like an upside-down T, an up tack perhaps?)

    The trouble is the up tack does not display differently whether the check box is checked or not. I don't think this is a formatting issue so I was wondering if it's possible for the code to replace the Checked or Not Checked with perhaps a symbol that Excel can read, like "X" & "Y"?

    I hope I have explained my issue succinctly and if you have come across something like this before and might be able to help please let me know.

    Thanks for all your help Paul - it's very very much appreciated

  2. #22
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    The resulting transfer in the Excel cell is this symbol:  (I don't know if this is displaying correctly but it's like an upside-down T, an up tack perhaps?)
    That's because .Range.Text gets just the 'text' of the range, but the checkbox formfields don't have text as such, just a true/false state. What you need to do, then, is to pre-process the table to convert all checkbox formfields to something meaningful (e.g. 1/0, TRUE/FALSE, CHECKED UNCHECKED). the simplest is 1/0:
    Dim wdCell As Word.Cell, wdFmFld As Word.FormField
    ...
    With wdRng                                      
    If .Tables.Count > 0 Then 
    With .Tables(1)
    For Each wdFmFld In .Range.FormFields
    wdFmFld.Range.Text = wdFmFld.Result
    Next
    WkSht.Cells(i, 3) = Replace(Replace.Range.Text, Chr(13) & Chr(7) & Chr(13) & Chr(7), Chr(10)), Chr(13) & Chr(7), Space(4))
    End With
    End If
    End With
    ... etc
    This assumes, of course, the document's form protection is off when the macro is run.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #23
    VBAX Regular pk247's Avatar
    Joined
    Feb 2014
    Posts
    64
    Location
    Hi Paul, thanks for offering your help with this...

    I just popped your code in (including the Dim...) but I'm getting a "Compile Error Expected: End of Statement" message and then the comma at Chr(10)), is highlighted blue. Is there maybe a change that can help at all please?

    Cheers! You're an absolute legend for helping and knowing how to do all this!

  4. #24
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Sorry, a bracket disappeared somehow!

    Change:
    WkSht.Cells(i, 3) = Replace(Replace.Range.Text, Chr(13) & Chr(7) & Chr(13) & Chr(7), Chr(10)), Chr(13) & Chr(7), Space(4))
    to:
    WkSht.Cells(i, 3) = Replace(Replace(.Range.Text, Chr(13) & Chr(7) & Chr(13) & Chr(7), Chr(10)), Chr(13) & Chr(7), Space(4))
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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