vba courses london - table macro
Microsoft Office Training verified by visa - mastercard securecode about microsoft training company london ukadd this page to your favourites/bookmarksAdd to favourites
view a printable version of this pagePrintable version
email this page to somebodyEmail this page
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft VBA Training and help » vba courses london - Table Macro

vba courses london - Table Macro

The UK's most regular instructor-led training courses.
Training information: vba courses london · Excel london

resolvedResolved · Low Priority · Version Standard

Table Macro

John has attended:
Excel VBA course

by - delegate John [1 post] (2006 Dec 4 Mon, 09:47) replyReply

If anyone can see fault in the macro below please help me.
I use this macro to open outlook e mails and format the contents into a table. each time only a small amount of lines are produced as tables the rest as one continous column. any help appreciated

thanks

John






Sub GetHMASplits()
Dim myNameSpace As NameSpace
Dim myMailbox As String
Dim myInbox As MAPIFolder
Dim myUnreadFolder As MAPIFolder
Dim myReadFolder As MAPIFolder
Dim myUnreadMailItem As Object
Dim strBranchCode As String
Dim strBody As String
Dim intFullLength As Integer
Dim NextInString
Dim strHMA As String
Dim myInspector As Inspector

Dim myExcel As Excel.Application
Dim myWkb As Workbook
Dim myWks As Worksheet
Dim myRowNo As Integer

'Make reference to inbox
Set myNameSpace = ThisOutlookSession.GetNamespace("Mapi")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
'Make reference to HMA folders
myMailbox = "MailBox - $Finance Heal Regions"
Set myUnreadFolder = myNameSpace.Folders(myMailbox).Folders("HMA Unread")
Set myReadFolder = myNameSpace.Folders(myMailbox).Folders("HMA Read")

Set myExcel = New Excel.Application
myExcel.Visible = True
Set myWkb = myExcel.Workbooks.Add
Set myWks = myWkb.Worksheets(1)
myRowNo = 1
'Process until the unread message folder is empty
Do Until myUnreadFolder.Items.Count = 0
'Make a reference to the last email received
Set myUnreadMailItem = myUnreadFolder.Items.Item(1)
'Check to see if the item is a mail item
'If not, move the item to the Other Items folder
If myUnreadMailItem.Class <> olMail Then
myUnreadMailItem.Move myInbox
Else
'Check to see what the subject of the mail is and process as appropriate
If Mid(myUnreadMailItem.Subject, 6, 15) = "HMA Bonus Split" Then
strBranchCode = Left(myUnreadMailItem.Subject, 4)
strBody = myUnreadMailItem.Body
Do Until InStr(1, strBody, strBranchCode, 1) = 0
NextInString = InStr(2, strBody, strBranchCode, 1)
If NextInString = 0 Then
strHMA = strBody
strBody = ""
Else
strHMA = Left(strBody, NextInString - 1)
strBody = Right(strBody, Len(strBody) - Len(strHMA))
End If
myWks.Cells(myRowNo, 1) = strHMA
myRowNo = myRowNo + 1
Loop
Set myInspector = myUnreadMailItem.GetInspector
myInspector.CurrentItem.UnRead = False
myInspector.Close olDiscard
Set myInspector = Nothing
myUnreadMailItem.Move myReadFolder
Else

End If
End If
Loop
'Tidy up the data
myWkb.Activate
myWks.Activate
If myWks.Range("A1") <> "" Then
myWks.Columns("A:A").TextToColumns Destination:=myWks.Range("A1"), _
DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1))
myWks.Cells.EntireRow.AutoFit
myWks.Cells.EntireColumn.AutoFit
myWks.Range("A1").Select
End If
'Free memory
Set myNameSpace = Nothing
Set myInbox = Nothing
Set myUnreadFolder = Nothing
Set myReadFolder = Nothing
Set myUnreadMailItem = Nothing
Set myInspector = Nothing
Set myExcel = Nothing
Set myWkb = Nothing
Set myWks = Nothing
End Sub

RE: Table Macro

by - trainer David gold contributer[428 posts] (2006 Dec 12 Tue, 09:44) replyReply

Hi John

Your problem is proving quite complex, so far both our VBA trainners have looked at your code, along with a myself who has high level programming language knowledge (Java, C, C++). I am sorry to say that so far we have been unable to spot the problem that you have.

I would ask that if you have got any further with the problem, could you post back and let us know, as we are continuing to work on this problem for you.

Some advise that I think will be useful for you, is that when coding you should go through and write code comments as you go, so both yourself and others know exactly what your code is meant to be doing at each point. This will make your code much clearer to read for people that have not worked on coding it.

If we find an answer, we will get back to you as soon as possible.

David


Related articles

· What Is Microsoft Excel VBA and How Can It Help You Work Smarter?
· Company Roles in Visual Basic Training
· Introduction to Visual Basic for Applications
· Should You Send Managers To VBA Training?
· Visual Basic Returns To The Macintosh

Vba tip:

Use VbNullString instead of

When needing to default a String variable back to it's default of "" use vbNullString as in the following example:

Sub ClearText()

Dim strEmpName As String

strEmpName = "John Smith"
MsgBox strEmpName

strEmpName = vbNullString
MsgBox strEmpName

End Sub

View all VBA hints and tips

Institute of IT Training - Accredited Training Provider Microsoft Certified Partner
microsoft office
Microsoft Office Specialist Authorised Testing Centre (MOS and MCAS)

Prodigy Platinum Learning Partner

Institute of IT Training - Accredited Training Provider Association of Computer Trainers Valid HTML 4.01 Transitional
Valid CSS Markup

secure online payments - visa - mastercard

Mini sitemap. These are the main areas of our web site. Full sitemap.

Training by application Main information pages See also

Access courses
DreamWeaver courses
Excel courses
MS Project courses
Outlook courses
PowerPoint courses
VBA courses
Word courses
(more...)

Public scheduled courses
On-site training
Closed company courses

Microsoft Office training
Pricing and availability
Training schedule
Training venues

Access training
Dreamweaver training
Excel training
MS Project training
PowerPoint training

London Computer Training
Computer Training London

Microsoft Access training
Microsoft Excel training
Microsoft Project training
Microsoft Outlook training
Microsoft Powerpoint training
Microsoft Word training

Time Management Course London

Interested in Access training? Please see the following pages:
microsoft access courses · microsoft training access course
microsoft+access+training · access courses in london

Training Information

Training Articles

AddThis Social Bookmark Button What's this?
Add to Del.icio.us Add to Facebook Add to Digg Add to Reddit Add to Google Add to Yahoo Add to Diigo Add to Mr. Wong Add to Linkarena Add to Power Oldie Add to Folkd Add to Jumptags Add to Upchuckr Add to Simpy Add to StumbleUpon Add to Slashdot Add to Netscape Add to Furl Add to Spurl Add to Blinklist Add to Blogmarks Add to Technorati Add to Newsvine Add to Blinkbits Add to Ma.Gnolia Add to Smarking Add to Netvouz