Consulting

Results 1 to 7 of 7

Thread: Prevent Styles Change

  1. #1

    Prevent Styles Change

    Hello,

    I am using Word 2010, I have a set of styles defined in the word, but while putting data from different word files (having with different styles), the styles in my word document gets very much disturbed.

    Please can someone let me know if there is a vba code, which when run on my word doc, prevents the styles.

    Thanks

  2. #2
    How are you 'putting data from different files'? If you are pasting data and you want it to match the data at the cursor, Select Paste Special > Unformatted text or use a macro
    Sub PasteUnfText()
        On Error GoTo err_Handler
        Selection.PasteSpecial DataType:=wdPasteText, _
                               Placement:=wdInLine
        End
    lbl_Exit:
        Exit Sub
    err_Handler:
        Beep
        GoTo lbl_Exit
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Actually the word document gets shared with many users and then everyone input their content and share ahead. During this process, many data is pasted from many other documents by different users into the main document. This results in the list of styles getting disturbed and many new unwanted styles are added in the main document.

  4. #4
    Even if you restrict editing to a limited number of styles, pasting text will screw that up. I think you will find that training of the people involved is the most practical solution.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    You might try using Document Restrictions to control the way styles are pasted in to see if it works for you

    When I pasted some Heading3 text into a restricted document, it went in as Normal

    You can add a PW, but it will take blanks also
    Attached Images Attached Images
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    Thank you so much gmayor and Paul for your reply. Sorry for the delay in replying as I have been searching some more ways out, but it didn't work yet.

    @gmayor, had tried that out but some people are simply difficult to train and still want to follow their own style of working.

    @Paul, tried out the restriction option, that too didn't work as required.

    I guess will have to check for a code which gets activated as soon as someone paste anything from the clipboard and ask them whether to paste as normal text or some existing style of our choice. Guys, Is there a possibility to create such a code in vba for word?

  7. #7
    Found some info while googling. Should use this piece of code and some steps given below.

    Sub PasteUnformatted()
    Selection.PasteSpecial DataType:=wdPasteText
    End Sub


    Next step is to tell word to run macro every time you press Ctrl+V.
    I am using word 2010
    > Click File Menu > Options
    > Click Customize Ribbon > Keyboard shortcuts > Customize...
    > Categories box > select 'Macros'
    > In the Macros box > choose your macro (in this case, PasteUnformatted)
    > Click inside the "Press new shortcut key" box and hit Ctrl+V on your keyboard.
    > Click Assign

    Whenever i use this process, the text maybe copied from anywhere, while doing ctrl+v, it paste the text as unformatted text.

    Please can someone help me in altering this code, so that it retains any hyperlinks attached to any text while pasting in the document.

    Thanks.

Posting Permissions

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