PDA

View Full Version : Prevent Styles Change



magnel
10-02-2015, 01:35 PM
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

gmayor
10-03-2015, 12:35 AM
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

magnel
10-03-2015, 01:39 AM
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.

gmayor
10-03-2015, 02:34 AM
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.

Paul_Hossler
10-06-2015, 07:54 AM
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

magnel
10-10-2015, 12:24 PM
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?

magnel
10-11-2015, 11:18 AM
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.