Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-13-2014, 04:45 AM
Tommes93 Tommes93 is offline formatting from word in xml Windows 7 64bit formatting from word in xml Office 2007
Novice
formatting from word in xml
 
Join Date: Mar 2014
Posts: 9
Tommes93 is on a distinguished road
Default formatting from word in xml


Hello
i have written a code that creates a xml file from a word document.
sometimes a paragraph from the word document hase different formattings
for example the first two words are written strong.
at this point i copied the hole range into a string that gets printed into a xml file.
the problem is that in the xml file i loose all the formattings like bold italic or underlined.
can you help me with this problem?
Reply With Quote
  #2  
Old 08-13-2014, 06:25 AM
macropod's Avatar
macropod macropod is offline formatting from word in xml Windows 7 32bit formatting from word in xml Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The problem is "i copied the whole range into a string". By definition, strings don't contain any formatting information.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 08-13-2014, 06:27 AM
Tommes93 Tommes93 is offline formatting from word in xml Windows 7 64bit formatting from word in xml Office 2007
Novice
formatting from word in xml
 
Join Date: Mar 2014
Posts: 9
Tommes93 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
The problem is "i copied the whole range into a string". By definition, strings don't contain any formatting information.
thanks i kinda knew that this will be the problem, thats why i mentioned it.

but any idea how i can go around this problem.

is it possible to search for formatted words only in my range that i am working with.

i need to put "<strong>" infront of the bold words and "</strong>" after them.
Reply With Quote
  #4  
Old 08-13-2014, 06:35 AM
macropod's Avatar
macropod macropod is offline formatting from word in xml Windows 7 32bit formatting from word in xml Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You really haven't provided anywhere near enough information for anyone to work with. You've supplied no code, no source material or an example of what it's supposed to look like at the destination. I can't even tell from what you've posted whether strong should end up in the output looking like strong or <b>strong</b>, for example.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 08-13-2014, 06:42 AM
Tommes93 Tommes93 is offline formatting from word in xml Windows 7 64bit formatting from word in xml Office 2007
Novice
formatting from word in xml
 
Join Date: Mar 2014
Posts: 9
Tommes93 is on a distinguished road
Default

alright.
so the code is not really necessary. i go from heading to heading and look what is unter the heading. if there is a table i go from wdCell to next wdCell and work with the cells.
Code:
For Each wdCell In ActiveDocument.Tables(ThisTableNumber).Range.Cells

Set Rng1 = wdCell.Range
Rng1.End = Rng1.End - 1
If Rng1.Font.Bold = True Then
        Set Rng2 = wdCell.Next.Range
        Rng2.End = Rng2.End - 1
        Select Case Rng1.Text
            Case "Name": TestcaseString = TestcaseString & "<name>" & Rng2 & "</name>" & vbCrLf
Now the problem is:
if the Rng2 looks like: "Hello, This is Tom. Im 21 yrs old." the whole formatting gets lost.
my xml file needs this formatting. a bold word needs to look like "<strong>word</strong>" in the xml file.
and this is where i need some help or ideas.
Reply With Quote
  #6  
Old 08-13-2014, 07:19 AM
macropod's Avatar
macropod macropod is offline formatting from word in xml Windows 7 32bit formatting from word in xml Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

There are some serious issues with your code snippet:
1. unless the whole cell range is bold, your code won't recognise it;
2. it unnecessarily processes every cell;
3. by referencing wdCell.Next.Range you're liable to produce an error when wdCell inevitably ends up as the last cell in the table; and
4. there is no indication of any xml file existing for the output.

Without knowing more about the table structure, there's not much more help I can give on that front. That said, applying the tags really doesn't require testing the contents of each & every cell. It can be done far more efficiently via Find/Replace. For example:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = ""
    .Format = True
    .Font.Bold = True
    .Forward = True
    .Wrap = wdFindStop
    .Execute
  End With
  Do While .Find.Found
    .Text = "<strong>" & .Text & "</strong>"
    .Font.Bold = False
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = ""
    .Format = True
    .Font.Italic = True
    .Forward = True
    .Wrap = wdFindStop
    .Execute
  End With
  Do While .Find.Found
    .Text = "<emphasis>" & .Text & "</emphasis>"
    .Font.Italic = False
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 08-14-2014, 12:50 AM
Tommes93 Tommes93 is offline formatting from word in xml Windows 7 64bit formatting from word in xml Office 2007
Novice
formatting from word in xml
 
Join Date: Mar 2014
Posts: 9
Tommes93 is on a distinguished road
Default

thank you for your code.
the code i posted is just a part of my whole code.
my code is as almost finished and works fine for the tables.
its just the problem with formatting.
your code works fine until this point:
Code:
  Do While .Find.Found
    .Text = "<strong>" & .Text & "</strong>"
    .Font.Bold = False
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
when the do while loop starts, it wont do it for only one cell or only the table. it goes through the whole document and changes every bold word. but it should do only one cell or a range i set.

at one point i set a range with this code
Code:
Do Until Selection.Style Like "Überschrift*" = True
                Selection.MoveDown Unit:=wdParagraph, count:=1
            Loop
            ende = Selection.End
            Set bereich = ActiveDocument.Range(anfang, ende)
or the code for the cells
Code:
For Each wdCell In ActiveDocument.Tables(ThisTableNumber + 1).Range.Cells

    Set Rng1 = wdCell.Range
    Rng1.End = Rng1.End - 1
    If Rng1.ListFormat.ListType = 3 Then
        If Steps = False Then
            TestcaseString = TestcaseString & "<steps>" & vbCrLf
            Steps = True
        End If
        
        Set Rng2 = wdCell.Next.Range
now the code you posted should change only this range.
Reply With Quote
  #8  
Old 08-14-2014, 01:00 AM
macropod's Avatar
macropod macropod is offline formatting from word in xml Windows 7 32bit formatting from word in xml Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Tommes93 View Post
when the do while loop starts, it wont do it for only one cell or only the table. it goes through the whole document and changes every bold word.
That's because I didn't provide any code to limit the range. Without knowing more about your document, which you seem reluctant to provide, I can't do that; you'll have to do it yourself, using an InRange test, along the lines of:
Code:
Do While .Find.Found
    If .InRange(some predefined range) Then
     ' do stuff here
    Else: Exit Do
    End If
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting contents after Tab of continuous lines or formatting specific area of word pawii Word 1 05-12-2014 05:24 AM
formatting from word in xml Formatting is restricted in Word 2007 but not in Word 2010 Word2007User Word 2 01-11-2014 06:33 PM
formatting from word in xml Word 2013 vs Word 2010 formatting issue? rhoyt Word 1 12-07-2013 09:40 AM
formatting from word in xml Formatting from PDF to WORD goldfish Word 8 04-25-2011 04:50 PM
formatting from word in xml Word Formatting Peter B. Word 5 05-10-2006 08:13 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft