Jump to content
Macro Express Forums

Paste Text Color


robdotcalm

Recommended Posts

Hi,

 

Depends how desperate you are! Each Office app may need its own (Word97 easier - you don't need to create a Word macro.

If I knew Office better, one would hope there's an easier way!

// Word2003 paste blue

// You need to assign macro to "ALT-B" in WOrd which sets the colour blue you want

Text Type: <ALT><ALT>ik

Wait For Window Title: "Bookmark"

Text Type: StartColour<ALT>a

Wait For Window Title: "Microsoft Word"

Clipboard Paste

Text Type: <F8><CONTROL>g

Wait For Window Title: "Find and Replace"

Text Type: <ALT>ob<ALT>eStartColour<ENTER>

Delay 100 Milliseconds

Text Type: <ALT>t<ESC>

Wait For Window Title: "Microsoft Word"

Text Type: <ALT>b

Text Type: <END>

Text Type: <ESC><ALT><ALT>of

Wait For Window Title: "Font"

Text Type: <ALT>c<ARROW UP><ARROW DOWN><ENTER><ALT>h<ALT>h<ENTER>

<REM2:Word2003 paste blue><REM2:You need to assign macro to "ALT-B" in WOrd which sets the colour blue you want><TEXTTYPE:<ALT><ALT>ik><WAITWIN2:000010:000000:Bookmark><TEXTTYPE:StartColour<ALT>a><WAITWIN2:000010:000000:Microsoft Word><CLIPP><TEXTTYPE:<F8><CONTROL>g><WAITWIN2:000010:000000:Find and Replace><TEXTTYPE:<ALT>ob<ALT>eStartColour<ENTER>><IMSD:100><TEXTTYPE:<ALT>t<ESC>><WAITWIN2:000010:000000:Microsoft Word><TEXTTYPE:<ALT>b><TEXTTYPE:<END>><TEXTTYPE:<ESC><ALT><ALT>of><WAITWIN2:000010:000000:Font><TEXTTYPE:<ALT>c<ARROW UP><ARROW DOWN><ENTER><ALT>h<ALT>h<ENTER>>

<REM2:Word97 paste blue><TEXTTYPE:<ALT><ALT>ik><WAITWIN2:000010:000000:Bookmark><TEXTTYPE:StartColour<ALT>a><WAITWIN2:000010:000000:Microsoft Word><CLIPP><TEXTTYPE:<F8><CONTROL>g><WAITWIN2:000010:000000:Find and Replace><TEXTTYPE:<ALT>ob<ALT>eStartColour<ENTER>><IMSD:100><TEXTTYPE:<ALT>t<ESC>><WAITWIN2:000010:000000:Microsoft Word><TEXTTYPE:<ESC><ALT><ALT>of><WAITWIN2:000010:000000:Font><TEXTTYPE:<ALT>c<HOME>bb<ENTER><ENTER>><WAITWIN2:000010:000000:Microsoft Word><TEXTTYPE:<END>><TEXTTYPE:<ESC><ALT><ALT>of><WAITWIN2:000010:000000:Font><TEXTTYPE:<ALT>c<HOME>b<ENTER><ENTER>>

What do you think?!

Randall

Link to comment
Share on other sites

hi, Rob,

 

Here's a playable macro you can import which writes its own "vbscript" to do your job in word03; (import to your library file?"

// paste clipboard to Word as Blue text

// path Registry Name as env var; %Reg%

Variable Set String %T1% "HKEY_CURRENT_USER\Software\Professional Grade Macros\PGM Functions\Swap\"

Variable Modify String: Save %T1% to Environment Variable

// Set Colour to BLUE

Variable Set String %T1% "&HFF0000"

Write Registry String: "%Reg%FontColour"

// Set "ClipBoard" registry entry to clipboard contents

Variable Set String %T1% from Clipboard

Write Registry String: "%Reg%Clipboard"

// Get the ME3 folder name.

Set Variable %T4% to "Installation Path"

// Generate the VBS script. NOTE: To view this script copy it to your clipboard and paste it

Variable Set String %T98% "%T4%\WordPaste.vbs"

If Not File Exists "%T98%"

  Clipboard Start Copy

    Text Type: Set WshShell = WScript.CreateObject("WScript.Shell")

Dim FontColour, RegDir : RegDir ...

  Clipboard End Copy

  Variable Set String %T1% from Clipboard

End If

If File Exists "%T98%"

  // Launch the VBS script and wait until it is done. Set the Delay on the Advanced tab to zero.

  Program Launch: "%T98%"

Else

  // Save the VBS script to the temp folder.

  Variable Modify String: Save %T1% to Text File

  Wait for File Ready: "

  Program Launch: "%T98%"

End If

Macro Return

<REM2:paste clipboard to Word as Blue text><REM2:path Registry Name as env var; %Reg%><TVAR2:01:01:HKEY_CURRENT_USER\Software\Professional Grade Macros\PGM Functions\Swap\><TMVAR2:19:01:00:000:000:Reg><REM2:Set Colour to BLUE><TVAR2:01:01:&HFF0000><REGWSTR:1:%Reg%FontColour><REM2:Set "ClipBoard" registry entry to clipboard contents><TVAR2:01:03:><REGWSTR:1:%Reg%Clipboard><REM2:Get the ME3 folder name.><VSETMISC:T4:Installation Path><REM2:Generate the VBS script. NOTE: To view this script copy it to your clipboard and paste it><TVAR2:98:01:%T4%\WordPaste.vbs><IFOTH:09:2:%T98%><BEGCLIP><TEXTTYPE:Set WshShell = WScript.CreateObject("WScript.Shell")
Dim FontColour, RegDir : RegDir ="HKCU\Software\Professional Grade Macros\PGM Functions\Swap\"
FontColour=WshShell.RegRead(RegDir& "FontColour")
ClipBoard = WshShell.RegRead(RegDir& "ClipBoard")
Set objWord = GetObject(, "Word.Application")
objWord.Selection.Font.Color = FontColour
objWord.Selection.TypeText(ClipBoard)><ENDCLIP><TVAR2:01:03:><ENDIF><IFOTH:01:2:%T98%><REM2:Launch the VBS script and wait until it is done. Set the Delay on the Advanced tab to zero.><LAUNCHDEL2:0:00%T98%><ELSE><REM2:Save the VBS script to the temp folder.><TMVAR2:17:01:00:000:000:%T98%F><WFREADY:000000:000005:000000%T98%>LAUNCHDEL2:0:00%T98%><ENDIF><MRETURN>

Best, Randall

PS - The "Wait" file ready corrected; re-loaded (though would work 2nd time anyway?)

wordVBSblue.mxe

Edited by randallc
Link to comment
Share on other sites

excel is painful, but here goes! - it will sometimes need to minimise Excel and restore before pasting!

// paste clipboard to Excel as Blue text

If Not Program Name "excel.exe" running

  Text Box Display: Error

  Macro Stop

End If

// path Registry Name as env var; %Reg%

Variable Set String %T1% "HKEY_CURRENT_USER\Software\Professional Grade Macros\PGM Functions\Swap\"

Variable Modify String: Save %T1% to Environment Variable

// Set Colour to BLUE

Variable Set String %T1% "5"

Write Registry String: "%Reg%FontColour"

// Set "ClipBoard" registry entry to clipboard contents

Variable Set String %T1% from Clipboard

Write Registry String: "%Reg%Clipboard"

// Get the ME3 folder name.

Set Variable %T4% to "Installation Path"

// Generate the VBS script. NOTE: To view this script copy it to your clipboard and paste it

Window Restore: "Microsoft Excel -"

Variable Set String %T98% "%T4%\ExcelPaste.vbs"

If Not File Exists "%T98%"

  Clipboard Start Copy

    Text Type: Set WshShell = WScript.CreateObject("WScript.Shell")

Dim FontColour, RegDir : RegDir ...

  Clipboard End Copy

  Variable Set String %T1% from Clipboard

  Delay 250 Milliseconds

  // Save the VBS script

  Variable Modify String: Save %T1% to Text File

  Wait for File Ready: "

End If

// Launch the VBS script and wait until it is done. Set the Delay on the Advanced tab to zero.

Program Launch: "%T98%"

Delay 250 Milliseconds

Read Registry String: "%Reg%Error"

If Variable %T1% = "ErrorVBS"

  Activate Window: "Microsoft Excel -"

  Window Minimize: "Microsoft Excel -"

  Wait Window Lose Focus: "Microsoft Excel -"

  Window Restore: "Microsoft Excel -"

  Program Launch: "%T98%"

End If

Macro Return

<REM2:paste clipboard to Excel as Blue text><IFOTH:14:1:excel.exe><TBOX4:T:1:CenterCenter000278000200:000:ErrorExcel not running!><MSTOP><ENDIF><REM2:path Registry Name as env var; %Reg%><TVAR2:01:01:HKEY_CURRENT_USER\Software\Professional Grade Macros\PGM Functions\Swap\><TMVAR2:19:01:00:000:000:Reg><REM2:Set Colour to BLUE><TVAR2:01:01:5><REGWSTR:1:%Reg%FontColour><REM2:Set "ClipBoard" registry entry to clipboard contents><TVAR2:01:03:><REGWSTR:1:%Reg%Clipboard><REM2:Get the ME3 folder name.><VSETMISC:T4:Installation Path><REM2:Generate the VBS script. NOTE: To view this script copy it to your clipboard and paste it><WRES:Microsoft Excel -><TVAR2:98:01:%T4%\ExcelPaste.vbs><IFOTH:09:2:%T98%><BEGCLIP><TEXTTYPE:Set WshShell = WScript.CreateObject("WScript.Shell")

Dim FontColour, RegDir : RegDir ="HKCU\Software\Professional Grade Macros\PGM Functions\Swap\"

    WshShell.RegWrite RegDir& "Error" , "", "REG_SZ"

FontColour=WshShell.RegRead(RegDir& "FontColour")

ClipBoard = WshShell.RegRead(RegDir& "ClipBoard")

On Error Resume Next  ' Defer error trapping.

Set objExcel = Getobject(, "Excel.Application")

If Err.Number <> 0 Then

Err.Clear  ' Clear Err object in case error occurred.

    Set objExcel = GetObject(, "Excel.Application")

    If Err.Number <> 0 Then

    WshShell.RegWrite RegDir& "Error" , "ErrorVBS", "REG_SZ"

Err.Clear

wscript.Quit

end if

end if

objExcel.Selection.Font.ColorIndex  = FontColour

objExcel.Selection.Value=ClipBoard

wscript.quit

><ENDCLIP><TVAR2:01:03:><IMSD:250><REM2:Save the VBS script ><TMVAR2:17:01:00:000:000:%T98%F><WFREADY:000000:000005:000000%T98%><ENDIF><REM2:Launch the VBS script and wait until it is done. Set the Delay on the Advanced tab to zero.><LAUNCHDEL2:0:00%T98%><IMSD:250><REGRSTR:1:%Reg%Error><IFVAR2:1:01:1:ErrorVBS><ACTIVATE2:Microsoft Excel -><WMIN:Microsoft Excel -><WAITWLF2:000010:000000:Microsoft Excel -><WRES:Microsoft Excel -><LAUNCHDEL2:0:00%T98%><ENDIF><MRETURN>

Let me know if probs!

Randall

ExcelVBSblue.mxe

Link to comment
Share on other sites

Thank you Randall. That works. Neat programming.

 

I've added to the program to make it do exactly what I want in Word. I place « at the start of paste and » at the end. Then I reconvert the color in Word to black by invoking a macro based on keystroke capture that changes the color to black. (basically it starts <alt> o to get to font change and then cycles thru the Font box with tabs and down arrows to get what I want.).

 

Cheers,

 

RobKelman.calm

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...