Printing VBA generated string at a particular location

KolGuyXcel

Board Regular
Joined
Jun 29, 2018
Messages
147
I'm applying filter to Column A & and then to Column B using VBA and then read the date from Column C. I'm using VBA to generate a string of around 40 to 50 character length (it would easily fit into less than half a line) from this data in Column C. I need to print this VBA generated string value at a specific location (around 3 cm from the top boundary and 4 cm from the left boundary of a 25 cm X 15 cm page). Is it possible to directly send this VBA generated string value directly to the printer?

Note: I'm not printing anything directly from this worksheet.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi,
Within your macro, have you already tested :
VBA Code:
Debug.Print strData
 
Upvote 0
Hi KolGuyXcel,

if you do not print anything from the worksheet I would use Word: in a template generate a TextFrame, place it accordingly, and use a code for getting the text over like (alter the names here to suit, code to be placed in workbook from which to print)

VBA Code:
Sub TextFromExcelToWord()
  
  Dim appWord     As Object
  Dim appDoc      As Object
   
  Set appWord = CreateObject("Word.Application")
  Set appDoc = appWord.Documents.Open(ThisWorkbook.Path & "\Sample Print.docx")
  appDoc.Bookmarks("YourTextFrame").Range.Text = Worksheets("YourName").Range("C6").Value
  appWord.Visible = True
  
  appWord.PrintOut Background:=False, Copies:=1
  
  appDoc.Close False
  Set appDoc = Nothing
  appWord.Quit
  Set appWord = Nothing

End Sub

Ciao,
Holger
 
Upvote 0
Hi KolGuyXcel,

if you do not print anything from the worksheet I would use Word: in a template generate a TextFrame, place it accordingly, and use a code for getting the text over like (alter the names here to suit, code to be placed in workbook from which to print)

VBA Code:
Sub TextFromExcelToWord()
 
  Dim appWord     As Object
  Dim appDoc      As Object
  
  Set appWord = CreateObject("Word.Application")
  Set appDoc = appWord.Documents.Open(ThisWorkbook.Path & "\Sample Print.docx")
  appDoc.Bookmarks("YourTextFrame").Range.Text = Worksheets("YourName").Range("C6").Value
  appWord.Visible = True
 
  appWord.PrintOut Background:=False, Copies:=1
 
  appDoc.Close False
  Set appDoc = Nothing
  appWord.Quit
  Set appWord = Nothing

End Sub

Ciao,
Holger
Good work-around. I'll make do with this until anything better.
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,638
Members
449,093
Latest member
Ahmad123098

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