Skip to main content

Posts

Showing posts with the label VBA

Excel not enough free memory

Opening files in Outlook shows an error message that there is not enough free memory to run the program.
But the computer has enough RAM installed and no other application is running on the computer except Outlook.
Office programs by default don't trust or block files originating from the Internet.
This is of course a good security settings but if this setting is getting to your nerves because even if the document that is coming from your own domain you are not able to open.
Or the file is originating from your own personal email account other than your company email but when it goes to your Outlook you cannot open it. This is the scenario where good and harsh words will start crossing your mind. You will need to ask what the heck is going on?

The Microsoft link below provide some solution on how this thing can be resolved.
The article title of the link below is:

Error message in Outlook: "There is not enough free memory to run this program. Quit one or more programs, and th…

Loop thru custom Textboxes name in VBA or VB.Net

Having a custom name in Textboxes, Listbox, ComboBox in VBA or VB.Net is a good strategy. So, it will be easy to debug the code or analyze the data.

If just relying on the default names is also good but it will get messy and it will be hard to control when there’s quite a few of textboxes, and list boxes. And the next person who will maintain the code will find it easier to debug or check the program when proper custom name is assigned to the controls. And that next person might be yourself. So, be gentle and be explicit in giving comments and assigning names to controls.

It doesn’t hurt to put a clear comment or an overview of what the piece of code does or what’s the input that the control is accepting. Because greediness breeds greediness, and it will bite back.

Anyway, to loop to all the custom or default names is quite easy.


Example, if there are 30 or more textboxes in a form. It can be done by a simple for loop like:

For x = 1 to 30

GetTboxvalue =    Me.Controls(“Textbox” & …

Set a graph or shape in Word behind text using VBA

How to set a graph or shape in Word so it stays behind the text using VBA?
In Word the option is to right click an object select wrap text and click the desired options such as behind text, in front of text and other options.
Setting a graph behind the text is quite useful, if you need to display some text that will be displayed together with the graph.
To do this via VBA is plain and simple, a one liner code.
ThisDocument.Shapes("NameOfTheChart").WrapFormat.Type = wdWrapBehind
wdWrapBehind is equal to set "Behind Text".
The one liner VBA code, of course it will apply to any shapes, circle, oval, square or other shapes not just a graph.
Code works on Word 2016, it may or may not word in previous version of  Word. 

Cheers. Till next time!


================================ Free Android Apps:
Click on links below to find out more:
Catholic Rosary Guide  for Android:
https://play.google.com/store/apps/details?id=com.myrosaryapp
http://quickbytesstuff.blogspot.sg/2014/09/how-t…

How to position a graph in word in a specific page?

Positioning a graph in word is necessary to put the graph in a page where the description or other supporting details for the graph will be placed.
But, how to place or put a graph in a specific page in a document?
By default, the graph will be generated in the first page of the document.
To position a graph in any page in the document is to create a bookmark.
If you know exactly where to put the graph, manually create a bookmark by clicking  “Insert” in the ribbon and selecting “Bookmark”.
After clicking “Bookmark” it will ask for a name and create any name to define the bookmark.
Once the bookmark has been named and created, you can call the bookmark via VBA.
Here’s the code to call and select a bookmark:
ActiveDocument.Bookmarks("graph1").Select
graph1 – is the name of the bookmark.
After selecting the bookmark via VBA, call the method to generate the chart.
Like:
'initialize and set graph type
 Set shp = ActiveDocument.Shapes.AddChart(xlXYScatterLines, -18, 80, 480, 3…

Word VBA to set x and y chart values

How to set X and Y values in Word VBA chart?

How to set vertical and horizontal values for a Word chart using VBA?

Code below assumes that you already have the necessary code to generate the chart.

This code below will only show how to set the X and Y values for a chart using VBA in a Word document.

Here's the code:

'Set value for Y axis or Vertical value

With cht.Axes(xlValue)

   .MinimumScale = 0
   .MaximumScale = 35
   .MajorUnit = 5
   .MinorUnit = 0

End With


' Set value for X axis or Horizontal value

With cht.Axes(xlCategory)

   .MinimumScale = 0
   .MaximumScale = 25
    .MajorUnit = 5
   .MinorUnit = 0    

End With




Cheers! Till next time.



================================ Free Android Apps:
Click on links below to find out more:
Excel Keyboard shortcuts guide https://play.google.com/store/apps/details?id=chrisjoms.myexcelapplicationguide
Linux Android App cheat sheet: https://play.google.com/store/apps/details?id=com.LinuxMobileKit Multiplication Table for early learnershttps://play.goo…

How to rename a chart in Word 2016

Do you want to check what’s the name of the chart in Word 2016?
Or you just want to rename the chart in Word 2016 to a name, that the chart represents?
Word 2016 default chart name is in sequence, like Chart1, Chart2, Chart3 and it follows this pattern depending on how may charts you have at your document.

If you have multiple charts in a word document, and you want the chart name it to something meaningful or what the chart itself is all about; it’s quite easy and straight forward to rename a chart, but the way to rename it is not conventional as the previous way of doing it in other version of office.
You can rename the chart via VBA code or using the GUI in Word itself.
To rename or check the name of the chart in Word 2016 or O365.
Click on the chart:

After clicking the chart, the "Chart Tools" will open at the Ribbon.
Click the "Chart Tools"  at the ribbon. Click on the "Format" tab.
Under Format tab, click on "Selection Pane", this will op…

PowerShell get folder capacity

Get the folder capacity using PowerShell via the old-school method.
Old-school since we will utilize the native “dir” command, just like the good old days of DOS.
PowerShell dir command output is not the same with the native windows system32 dir command line just like in DOS system.
The output will be in bytes since it is from the command line but of course, if you are command line junkie it will be easy to read even if the capacity is written in bytes.
First, fire up notepad write the dir command plus the full folder path of the specified folder in which you like to monitor or want to know the capacity.
 dir “c:\users\dmusic\music folder 001”
The path is enclosed in quotes since the folder has spaces and save the notepad as a batch file with “.bat” extension.
Open PowerShell command line window or PowerShell ISE and type the following command:
#change the path to where the batch file was saved
$folder_base_cap = d:\read_folder_cap.bat 
$ folder_base_cap | Select-String "bytes&qu…

Sort numbers, digits or figures in Excel 2016

To sort numbers, digits, or figures in Excel 2016 is quite straight forward.
There are two ways to do it via the Home tab or Data tab.
What is found on the Home tab is sorting of alphabets or A-Z option which can easily be seen beside the auto-sum function which is on the right most tab of the ribbon by default.
Screen shot below shows the sorting functionality found in Home tab.


The other way to sort by numbers, digits or figures in Excel 2016 is to click on “Data” click on “Sort” then an option will appear to sort by smallest to largest or largest to smallest.
A screen shot below shows where to find the function.


That’s it hopes it helps to make thing easier.


================================ Free Android Apps:
Click on links below to find out more:

Excel Keyboard shortcuts guide https://play.google.com/store/apps/details?id=chrisjoms.myexcelapplicationguide
Linux Android App cheat sheet: https://play.google.com/store/apps/details?id=com.LinuxMobileKit Multiplication Table for early learner…

Excel VBA set worksheet visibility

Set excel worksheet visibility by changing its property.
Simple and a one liner code to hide and unhide worksheet in Excel.
Sub Visible_Sheet()
Worksheets(1).Visible = 1  'Make the worksheet visible
End Sub
Sub Hide_RightClick_Unhide()
Worksheets(1).Visible = 0    'Hide Worksheet to Unhide Right click on Sheet name and unhide the worksheet
End Sub
Sub Super_Hide()
Worksheets("calcx").Visible = 2
 'Hide Worksheet but right click on Sheet name will not show whether the sheet is hidden or not
End Sub



Cheers! Till next time.

================================ Free Android Apps:
Click on links below to find out more:

Excel Keyboard shortcuts guide https://play.google.com/store/apps/details?id=chrisjoms.myexcelapplicationguide
Linux Android App cheat sheet: https://play.google.com/store/apps/details?id=com.LinuxMobileKit
Multiplication Table for early learners https://play.google.com/store/apps/details?id=com.TableMultiplication
Catholic Rosary Guide  for Android:
https://play.google.com/sto…

PowerShell validate list of email addresses

Validate list of email addresses in a text file and check which email is a valid email and which one has the incorrect format.
PowerShell code below can easily check or validate incorrect email, output will show true if valid email and false if the email is not valid.
To check list of valid emails PowerShell utilizes regex. This is useful to check typo errors when sending out mass email or a list of emails which has not yet been verified.

But of course, the code will not be able to check whether the emails are active or not.

#===============================
$reader = [System.IO.File]::OpenText("c:\all_emails.txt") #get-content can also be used
while($null -ne ($line = $reader.ReadLine())) {
    #$line     $regx="[a-z0-9!#\$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#\$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"
    [regex]::Match($line, $regx, "IgnoreCase ")  |  format-Table success, value -AutoSize }

#========…

How to escape in PowerShell

In bash script the backslash is use as escape sequence and even in Java programming.

But what's the equivalent of bash escape sequence in PowerShell?

Grave accent or back tick, which is found at the top left corner of the keybord below the "esc" key on some keyboard, This character "`" is the escape in PowerShell.

For example:

Write-host "This line is above `r`n and  `r`n this line is below"

Output is:
This line is above
 and
 this line is below

r is equal to carriage return character putting a backtick before r, `r tells PowerShell that r is not a character but a carriage return
n is a new line character putting a backtick before n, `n tells PowerShell that n is a new line character.

Another example:

$ sign in PowerShell is to indicate a variable

But what if you need to display a dollar sign as a character and not as a special character to declare a variable. Then we need to escape the dollar sign by prefixing a backtick before the character.

Exampl…