Skip to main content

Posts

Showing posts with the label Macro

Outlook does not display picture

Have you received an email saying please find the picture below, but the picture is on the attachment not on the body of email.

Or sending out a nice an beautiful layout of graphics hoping to impress a colleague or client only to find out that the the graphics doesn't display correctly in Outlook or either in the mobile phone.

HTML Tables has been a big help for web designers or developers before the CSS era or other good platforms at this time.

Well, if picture is not displaying properly in Outlook or mobile phone. Embedding or inserting the picture in a Table, seems to be a good quick solution in inserting pictures via Outlook and it will display properly in mobile phone also.

When composing email in Outlook, click on the Insert option and click on insert table. If sending two pictures, you can insert a two rows or two columns and insert the picture on each row or column.

After sending out the email, check the email in Outlook or mobile phone and if everything goes okay the pic…

VB.Net remove line feed or new line

In VB.net or any programming language, if the program requires getting data from external programs, results or data from third party software that needs to be processed  may or may not have expected desired output.

For example, getting a string from a third party software. String is quite straight forward and it's quite basic.

But the issue arises,  if the desired output requires a specific string or text and other text should be discarded or deleted. Regex or any other methods might help on getting the specific text or data.

One basic issue, if the string needs to be formatted in one line but a line feed or a new line keeps breaking the line.

The first instinct that I think of, is to use "Trim" function but it doesn't solve the issue. Trim, Ltrim or Rtrim just delete spaces but it doesn't delete line feed.

In VB.Net a line feed can easily be removed by this code snippet below:

Dim strNoLineFeed As String = String_with_Line_Feed.Replace(vbCr, "").Replac…

Excel VBA replace first or last character

Excel VBA code below will replace the first or last character of the cell value.

Use a test workbook with dummy data, to test the VBA code.

Works fine on Excel 2010.

Sub replaceChar()
'Replace Last Character

Dim i, ilength As Integer
Dim strCellValue, yCutString, zValue As String
Dim iRow, myColumn As Long

'specify the column where the values will be changed
myColumn = 2

'get the last row
iRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row

For i = 1 To iRow
On Error Resume Next

strCellValue = Cells(i, myColumn).Value
ilength = Len(strCellValue) - 1

'left - will replace last character on the string
yCutString = Left(strCellValue, ilength)

' LastChar is the string that will be added to the end of the cell value
'Replace this with any desired value
zValue = yCutString + "LastChar"

'Display the value of the processed string
'press ctrl+break to stop the loop
MsgBox zValue


'uncomment this line to replace the value with the processed string
'specify…

Disable Replace Text in Word using VBA

In word while you are typing, Word is smart enough to replace typing errors.

But if you are not typing in English language, it will be a mess if word will automatically replace the word.

Solution is to disable the feature "Replace Text as you type."

This simple VBA code snippet will disable the options "Replace Text as you type".

Disable is set to "False".

Application.AutoCorrect.ReplaceText = False


It can be done manually by clicking on: (Word 2010 procedure)

1. File
2. Options
3. Proofing
4. Auto Correct Options
5. AutoCorrect Tab
6. Untick "Replace text as you type"
7. Click "OK" 2 times to exit

But the one liner VBA code is quite simple rather than clicking so many times.

To enable via VBA just set the value to True.

Word VBA macro get username

A Word VBA macro to get username and record the date and time the document was opened and closed.

Private Sub Document_Open() -- Will run the macro if the document is open

Private Sub Document_Close() -- Will run the macro if the document is close

To run the macro, create a text file on this location.

D:\DocMonitor\wordUserClose.txt

D:\DocMonitor\wordUserOpen.txt

Change the file name and the location to any path and any desired file name.

==============================

Private Sub Document_Open()

Dim xUserName As String
Dim xDate As String
xUserName = Application.UserName

Dim xfileSystem, xwriteStream

xDate = Now()

Set xfileSystem = CreateObject("Scripting.FileSystemObject")
'fs.CreateTextFile "D:\DocMonitor\wordUserOpen.txt"
Set xwriteStream = xfileSystem.OpenTextFile("D:\DocMonitor\wordUserOpen.txt", 8, 0)
xwriteStream.WriteLine vbCrLf

xwriteStream.WriteLine Open Date and Time
xwriteStream.WriteLine xDate
xwriteStream.WriteLine xUserName
xwriteStream.Close


Set xfileS…

Unable to print word 2010 document

Assuming the printer is setup properly, and able to print from PDF, notepad or other software and also able to print from printer driver test page.
But when printing a specific word document in Word 2010, it will just show "Not responding" the document will hang and will not print.
There is no restriction set on the document but cannot print.
Try steps below:

Click on the "File" tab, click on the "Review" menu.
From the "Review" tab, select "tracking" change the option from:
"Final: Show Markup" to "Final".

Check image below:


Save the document or save it to a different file name.
And try printing again, if everything goes right the document will be able to print.
Paper tray settings will also cause a problem with printing the document.

Documents from another party that retain printer settings on the document will not print if the printer of the other party does not have same settings on what is currently retain on …