Format Only Field "AppsName"

jim may

Well-known Member
Joined
Jul 4, 2004
Messages
7,486
WIthin my Excel Code I incorporate Word to Print out Information in the COMMENTS of a certain Cell. Here are the code lines as they relate to placing the values into the New Word Document. I'd like to be able to Format the Variable AppsName - Font.size 16; Bold; and Underlined, but I'm unsure at to how to proceed. Can someone assist, showing me the proper syntax?

TIA,

Jim

Code:
WordObj.Documents.Add
With WordObj.Selection
.TypeParagraph
.TypeText Text:="It is now:      " + Format(Now(), "mmm-dd-yyyy hh:mm")
.TypeParagraph
.TypeText Text:="My Comment History-To-Date on         " + AppsName + "          is as follows:"
.TypeParagraph
End With
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi Jim,

Try something along the lines of:
Code:
Dim wdRng As WordObj.Range
With Selection
  .TypeText Text:=vbCr & "It is now:      " + Format(Now(), "mmm-dd-yyyy hh:mm") _
    & vbCr & "My Comment History-To-Date on         "
  Set wdRng = Selection.Range
  wdRng.Start = wdRng.End
  .TypeText Text:=AppsName
  wdRng.End = .Range.End
  .TypeText Text:="          is as follows:" & vbCr
  With wdRng.Font
    .Bold = True
    .Underline = 1 'wdUnderlineSingle
    .Size = 16
  End With
End With
 
Upvote 0
Thanks MicroPod;

I'm afraid I'm so deficient at undestanding code that I do not know how to incorporate or change my existing code to accomodate your offering.

In my Dim lines (before I consider your suggestion) I have Dim WordObj as Object
Leaving this line intact as I open up a line below it and enter your Dim wdRng as WordObj.Range -- it takes it -- but when I run the code immediately afterwards I get
compile error with the cursor sitting on the Line Dim wdRng as WordObj.Range

Any suggestions?
 
Upvote 0
Hi Jim,

OK, here's a stand-alone implementation that assumes you've set a reference to the Word object model:
Code:
Sub Demo()
Dim wdApp As Word.Application
Set wdApp = Word.Application
Dim wdDoc As Word.Document
Set wdDoc = wdApp.Documents.Add
Dim wdRng As Word.Range
With wdDoc.Range
  .InsertAfter vbCr & "It is now:      " + Format(Now(), "mmm-dd-yyyy hh:mm") _
    & vbCr & "My Comment History-To-Date on         "
  Set wdRng = wdDoc.Range
  wdRng.Start = wdRng.End
  .InsertAfter "AppsName"
  wdRng.End = .End
  wdRng.MoveEnd wdCharacter, -1
  .InsertAfter "          is as follows:" & vbCr
  With wdRng.Font
    .Bold = True
    .Underline = wdUnderlineSingle
    .Size = 16
  End With
End With
End Sub
Note: In this implementation, "AppsName" is passed as a string. Deleting the enclosing quotes will allow you to pass it as a variable. This implementation also avoids the use of selections, as using ranges is more efficient.
 
Upvote 0
Thanks macropod.

I will look over as soon as I can.
I appreciate your taking to time to help me.

Jim
 
Upvote 0

Forum statistics

Threads
1,225,549
Messages
6,185,594
Members
453,307
Latest member
addydata

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