protect layout / copy past with predifined lay-out settings

APOC [T.I.M.]

Board Regular
Joined
Jun 28, 2007
Messages
132
is there a simple way to "protect" the lay out of my worksheet in someway ???
I mean when I copy paste some info/text in my worksheet it's alway pasted in the default excel layout setting (arial 10) at least nearly all the time.

could I paste text by default with these settings?
Arrial Narrow 8 in the default (predifined) cell collor and no underline?
I guess I should use some vba code?
(and perhaps I can use this settings by default for all text in my worksheet by default?)
I did search but there are a lot and I mean a whole lot of topics but I still haven't found one which does what I want/need.

with kind regards
 
I'm trying something like this, but it's not quite working,
I guess somethings wrong with this line: ,,Dim MyDataObj As New DataObject'' (Excel 2002 SP3)

Code:
Sub CustomPaste()
 
Dim temp
 
'Ignore "TESTERtje" documents
If UCase(Left(ActiveDocument.AttachedTemplate.Name, 6)) <> "TESTERtje" And _
   LCase(ActiveDocument.AttachedTemplate.Name) <> "normal.dot" And _
   LCase(ActiveDocument.AttachedTemplate.Name) <> "normal.dotm" Then
        Selection.Paste
        'MsgBox "No TEST document, normal behaviour!", vbInformation
        Exit Sub
End If
 
If VariabeleExists("SkipCustomPaste") = True Then
    ActiveDocument.Variables("SkipCustomPaste").Delete
    Selection.Paste
    Exit Sub
End If
 
'check clipboad for data:
Dim MyDataObj As New DataObject
MyDataObj.GetFromClipboard
 
 
 
If MyDataObj.GetFormat(1) = True Then
    'Change layout pasted text into surrounding layout/format
    Selection.PasteAndFormat wdFormatSurroundingFormattingWithEmphasis
    MsgBox "Text pasted in default layout", vbInformation, "TESTERtje custom paste"
Else
    'Paste the rest, ie. images
    Options.PictureWrapType = wdWrapMergeInline
    temp = Selection.ParagraphFormat.LineSpacingRule
    Selection.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle
    On Error GoTo fout:
    Selection.Paste
    Selection.TypeParagraph
    Selection.ParagraphFormat.LineSpacingRule = temp
    MsgBox "row distance is 1" & vbCrLf & vbCrLf & _
    "(or else you will probably see a partial picture)", vbInformation, "TESTERtje custom paste"
End If
 
Exit Sub
 
fout:
'clipboard empty
Selection.ParagraphFormat.LineSpacingRule = temp
MsgBox "Niets op klembord of fout bij plakken!", vbExclamation, "TESTERtje custom paste"
 
End Sub
 
Last edited:
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
can't get the above code working in VBA (excel 2002 sp3)

I'd ecpesially like this part to work:
Code:
If MyDataObj.GetFormat(1) = True Then
    'Change layout pasted text into surrounding layout/format
    Selection.PasteAndFormat wdFormatSurroundingFormattingWithEmphasis
    MsgBox "Text pasted in default layout", vbInformation, "TESTERtje custom paste"
Else
    'Paste the rest, ie. images
    Options.PictureWrapType = wdWrapMergeInline
    temp = Selection.ParagraphFormat.LineSpacingRule
    Selection.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle
    On Error GoTo fout:
    Selection.Paste
    Selection.TypeParagraph
    Selection.ParagraphFormat.LineSpacingRule = temp
    MsgBox "row distance is 1" & vbCrLf & vbCrLf & _
    "(or else you will probably see a partial picture)", vbInformation, "TESTERtje custom paste"
End If
 
Exit Sub
 
fout:
'clipboard empty
Selection.ParagraphFormat.LineSpacingRule = temp
MsgBox "Niets op klembord of fout bij plakken!", vbExclamation, "TESTERtje custom paste"

in the above vba-code (previous post) the problem starts with this line:
Dim MyDataObj As New DataObject* <= isn't defined
Yeah! I was affraid of that, how should/could I get it to work, does anyone have an idea?

with kind regards, Tim
 
Upvote 0
capture the .copy / .past procedure

Isn't there in VBA some "simple" way to somehow capture the .copy / .past procedure?

ie. Selection.Paste and "mount" someway or another some Format/FormatSurrounding to it?
So that what's pasted automatically inherits the format of the surrounding cells (like one above and one below and if one is empty take the one that does have a format)
 
Upvote 0

Forum statistics

Threads
1,215,857
Messages
6,127,374
Members
449,382
Latest member
DonnaRisso

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top