Wednesday, 3 April 2013

auto increment (auto_increment) in Excel with VBA (auto generate line numbers)

I was asked a question the other day, I'm still not quite sure why this was important to the user (see as Excel has row numbers provided automatically) and its also very easy to type the numbers and then drag down / fill to generate the next number, anyway the user had a large Excel document that they wanted to have automatic line numbers at various points (almost like a list or bullet points in Word)

I knocked up a quick macro that seems to do the job for the user


Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
     
    If Target.Column > 1 And Target.Column <= 7 Then
   
        If Target.Row - 1 > 0 Then
            Cells(Target.Row, 1).Value = Target.Worksheet.Cells(Target.Row - 1, 1) + 1
        End If
      
    End If
End Sub



Wednesday, 13 March 2013

PowerPoint 2010 video problems "Microsoft Office PowerPoint Has Stopped Working"

I encountered a frustrating problem today, I’ve still not really worked out a “final” solution but here’s what I discovered.

A user has a number of power point presentations with videos linked (possibly embedded within) the videos are of mixed format.

The videos and presentations run perfectly on their laptop but on their assistants they do not. In fact on their assistance laptop Microsoft PowerPoint crashes when you try and open the presentation with the following error message “Microsoft Office PowerPoint Has Stopped Working”

I was able to open the presentations with PowerPoint 2003 (using Microsoft Compatibility pack), the base files are in 2007 format (.pptx), if PowerPoint 2003 won’t open the pptx file and you have the following error “No text converter is installed for this file type” simply download service pack 3 for Office 2003.

So people have suggested that once open in 2003 that you could try saving the file as a ppt, this works however I am concerned about what video functionality we may lose by doing this.

I found that by uninstalling VLC media player that I could now open the presentations in PowerPoint 2010 however I am unable to view any of the videos nor am I able to view any of the video properties. I managed to fix this by installing an earlier version of VLC media player (I opted for version 1.0.0 available from VLC’s ftp site http://download.videolan.org/pub/videolan/vlc/)

It seems that the videos in this presentation are “linked” a new feature in 2010 is embedded videos, I think I will investigate this and see if embedding the media resolves this issue.

Tuesday, 19 February 2013

Follow Up: Exchange / Outlook Nickname (NK2) contacts syncing to iPhone

OK, so in my last blog posted I talked about an annoying problem with setting up contacts with the iPhone and Exchange 2010 and while the work around I posted hid a lot of unnecessary contacts they are still actually on the device. This causes a problem for a lot of my mobile users as a number of them sync their contacts via blue tooth with their in car systems.

The first time I had one of them do this they reported that they had 1000+ contacts listed on their in car system.

A previous work around I had used for the BlackBerry was to move all the contacts to a secondary address book and then have them store only telephone numbers in their main 'Contacts' address book within Outlook. On the iPhone this doesn't work.

So here's how I solved this problem (or at least this is my work around)

Within Outlook export all the contacts from the address book to a CSV file.

Go to GMail and import the CSV

From GMail export the contacts to a vCard format.

Go to iCloud and import the vCard

Now setup your iPhone to only sync contacts from iCloud and not Exchange.

Seems a little messy really, Apple should really come up with a fix for this, as when my users add new contacts they will need to do it via the device/iCloud and then also in Outlook.

Tuesday, 29 January 2013

Exchange / Outlook Nickname (NK2) contacts syncing to iPhone

So I'm fairly new to iPhone (having had a BlackBerry for 4 years). Since setting my iPhone 5 to sync contacts, email etc with Exchange 2010 I've had a rather annoying issue, it seems that the iPhone picks up the "Suggested Contacts" folder, this means that my iPhone now has a contact for every single person that I've ever send an email to.

I read a couple of articles which suggest the way to fix the issue is to disable the suggest contacts, for me this would work fine, however the majority of my users use the suggested contacts. The solution is actually rather simple.

On the iPhone go to Contacts
Go to Groups
Check all the address books that you don't want to sync.

Wednesday, 28 November 2012

Export Folder Structure + Emails as MSG in Outlook

I came across the following VBA macro. While most people will want to backup their Outlook email via a PST file, some may want to export each message on its own. A single message can be saved by selecting "File - Save As" or by simply dragging the message from Outlook to the desktop, but if you want to do multiple messages while preserving a folder structure it is much more difficult.

In case the article is ever removed I will paste the macro below as well.
http://www.vbaexpress.com/kb/getarticle.php?kb_id=875#instr



Option Explicit

Sub SaveAllEmails_ProcessAllSubFolders()

Dim i As Long
Dim j As Long
Dim n As Long
Dim StrSubject As String
Dim StrName As String
Dim StrFile As String
Dim StrReceived As String
Dim StrSavePath As String
Dim StrFolder As String
Dim StrFolderPath As String
Dim StrSaveFolder As String
Dim Prompt As String
Dim Title As String
Dim iNameSpace As NameSpace
Dim myOlApp As Outlook.Application
Dim SubFolder As MAPIFolder
Dim mItem As MailItem
Dim FSO As Object
Dim ChosenFolder As Object
Dim Folders As New Collection
Dim EntryID As New Collection
Dim StoreID As New Collection

Set FSO = CreateObject("Scripting.FileSystemObject")
Set myOlApp = Outlook.Application
Set iNameSpace = myOlApp.GetNamespace("MAPI")
Set ChosenFolder = iNameSpace.PickFolder
If ChosenFolder Is Nothing Then
Goto ExitSub:
End If

Prompt = "Please enter the path to save all the emails to."
Title = "Folder Specification"
StrSavePath = BrowseForFolder
If StrSavePath = "" Then
Goto ExitSub:
End If
If Not Right(StrSavePath, 1) = "\" Then
StrSavePath = StrSavePath & "\"
End If

Call GetFolder(Folders, EntryID, StoreID, ChosenFolder)

For i = 1 To Folders.Count
StrFolder = StripIllegalChar(Folders(i))
n = InStr(3, StrFolder, "\") + 1
StrFolder = Mid(StrFolder, n, 256)
StrFolderPath = StrSavePath & StrFolder & "\"
StrSaveFolder = Left(StrFolderPath, Len(StrFolderPath) - 1) & "\"
If Not FSO.FolderExists(StrFolderPath) Then
FSO.CreateFolder (StrFolderPath)
End If

Set SubFolder = myOlApp.Session.GetFolderFromID(EntryID(i), StoreID(i))
On Error Resume Next
For j = 1 To SubFolder.Items.Count
Set mItem = SubFolder.Items(j)
StrReceived = ArrangedDate(mItem.ReceivedTime)
StrSubject = mItem.Subject
StrName = StripIllegalChar(StrSubject)
StrFile = StrSaveFolder & StrReceived & "_" & StrName & ".msg"
StrFile = Left(StrFile, 256)
mItem.SaveAs StrFile, 3
Next j
On Error Goto 0
Next i

ExitSub:

End Sub

Function StripIllegalChar(StrInput)

Dim RegX As Object

Set RegX = CreateObject("vbscript.regexp")

RegX.Pattern = "[\" & Chr(34) & "\!\@\#\$\%\^\&\*\(\)\=\+\|\[\]\{\}\`\'\;\:\<\>\?\/\,]"
RegX.IgnoreCase = True
RegX.Global = True

StripIllegalChar = RegX.Replace(StrInput, "")

ExitFunction:

Set RegX = Nothing

End Function


Function ArrangedDate(StrDateInput)

Dim StrFullDate As String
Dim StrFullTime As String
Dim StrAMPM As String
Dim StrTime As String
Dim StrYear As String
Dim StrMonthDay As String
Dim StrMonth As String
Dim StrDay As String
Dim StrDate As String
Dim StrDateTime As String
Dim RegX As Object

Set RegX = CreateObject("vbscript.regexp")

If Not Left(StrDateInput, 2) = "10" And _
Not Left(StrDateInput, 2) = "11" And _
Not Left(StrDateInput, 2) = "12" Then
StrDateInput = "0" & StrDateInput
End If

StrFullDate = Left(StrDateInput, 10)

If Right(StrFullDate, 1) = " " Then
StrFullDate = Left(StrDateInput, 9)
End If

StrFullTime = Replace(StrDateInput, StrFullDate & " ", "")

If Len(StrFullTime) = 10 Then
StrFullTime = "0" & StrFullTime
End If

StrAMPM = Right(StrFullTime, 2)
StrTime = StrAMPM & "-" & Left(StrFullTime, 8)
StrYear = Right(StrFullDate, 4)
StrMonthDay = Replace(StrFullDate, "/" & StrYear, "")
StrMonth = Left(StrMonthDay, 2)
StrDay = Right(StrMonthDay, Len(StrMonthDay) - 3)
If Len(StrDay) = 1 Then
StrDay = "0" & StrDay
End If
StrDate = StrYear & "-" & StrMonth & "-" & StrDay
StrDateTime = StrDate & "_" & StrTime
RegX.Pattern = "[\:\/\ ]"
RegX.IgnoreCase = True
RegX.Global = True

ArrangedDate = RegX.Replace(StrDateTime, "-")

ExitFunction:

Set RegX = Nothing

End Function

Sub GetFolder(Folders As Collection, EntryID As Collection, StoreID As Collection, Fld As MAPIFolder)

Dim SubFolder As MAPIFolder

Folders.Add Fld.FolderPath
EntryID.Add Fld.EntryID
StoreID.Add Fld.StoreID
For Each SubFolder In Fld.Folders
GetFolder Folders, EntryID, StoreID, SubFolder
Next SubFolder

ExitSub:

Set SubFolder = Nothing

End Sub


Function BrowseForFolder(Optional OpenAt As String) As String

Dim ShellApp As Object

Set ShellApp = CreateObject("Shell.Application"). _
BrowseForFolder(0, "Please choose a folder", 0, OpenAt)

On Error Resume Next
BrowseForFolder = ShellApp.self.Path
On Error Goto 0

Select Case Mid(BrowseForFolder, 2, 1)
Case Is = ":"
If Left(BrowseForFolder, 1) = ":" Then
BrowseForFolder = ""
End If
Case Is = "\"
If Not Left(BrowseForFolder, 1) = "\" Then
BrowseForFolder = ""
End If
Case Else
BrowseForFolder = ""
End Select

ExitFunction:

Set ShellApp = Nothing

End Function



Tuesday, 18 September 2012

Domain.com

So I dipped my toe into web development as a favor for a friend and it feels like I've been bitten through no real fault of my own. While the site design isn't necessarily what I would have chosen or gone with its was exactly what he wanted and it seems to work quite well. 

He wanted to put the site live and asked for my opinion on web hosting. Domain.com have been recommended by various online communities I visit for the last 4 or 5 years, they also have a pretty good ethical stance (they seem like saints compared to my regular hosting provider... GoDaddy) anyway despite good promotional offers and Domain.com are crap, hosted applications (phpBB, WordPress etc) are very very slow, and their customer service is no existent. It takes 3-4 days before someone even looks at any tickets you submit, they'll then comment and provide information unrelated to your actual problem, claim your issue has been fixed and then close the ticket so you have no chance of providing feedback OR confirming that the actual issue has been resolved. Its one big JOKE! We'll be waiting for the hosting to come up for renewal and then migrate away.

GoDaddy.com > Domain.com

Video File Conversion

It seems that a lot of video files these days are avi. This is a little annoying as the HP Touchpad doesn’t natively support avi files so I have to convert all my videos to mp4. I have used various converts in the past and had mixed results. Recently I found a great bit of open source software that works very well.
Check out http://handbrake.fr/ for all your video converting needs