Often we have clients who want Word to open without an initial document being displayed. This is usually because they don’t want the initial document based on the normal template. Doing a winword /a is no good, as it kills off all the other add-ins – so your DMS is usually killed off in the process, let alone all your other add-ins.

Life was simple in the days of Word 2003 – to get rid of the initial you could just do an ActiveDocument.Close in an AutoExec sub and you’re away. But that doesn’t work in 2010 as there no active document yet during the AutoExec.

So how did we get around it? Well it turns out we had to use the Document_Change event instead.

Within one of your startup templates, add a new Class object, call it AppEvents and insert the following code:

Option Explicit

Private WithEvents objApplication As Word.Application

Private Sub Class_Initialize()
objApplication = Word.Application
End Sub

Private Sub objApplication_DocumentChange()
On Error Resume Next
        If StartingUp Then
            If Documents.Count > 0 Then
                ‘ Close any new document created using normal.dot/normal.dotm
                If ActiveDocument.Name = ActiveDocument.Fullname And _
InStr(1, ActiveDocument.AttachedTemplate, “Normal.dot”, vbTextCompare) Then
StartingUp = False
                    Exit Sub
                End If
            End If
        End If
    End Sub

Now create a new module, call it AutoMacros (or anything else you like) and add the following code:

Option Explicit

Dim oAppEvents As AppEvents
Dim StartingUp As Boolean

Sub AutoExec()
StartingUp = True
        oAppEvents = New AppEvents
End Sub

So why add the StartingUp variable? Well if we don’t have it, then any new document you try to create based on Normal will automatically close. Whilst that doesn’t sound too bad in a lot of cases, it has one bad side effect – you can’t do a compare into a new document, as the new document that gets created is always based on Normal. There are probably a few other possible bad side effects too – but we didn’t bother looking any further after that one!

Have you had a play with watermarks in Word 2007 or 2010? It looks great – a nice little graphical drop down so you can see what you’re inserting, the ability to create custom watermarks, what’s not to like?

For simple documents, this works really well. The problem is once you come to a document with multiple sections, or with different page headers. For example, set up a document with a few sections, and make sure the “Link To Previous” setting is off. Now go to any section, and insert a new watermark. See – it looks good. But now look at the other sections – they don’t have the watermark. That’s not too big a deal – so you then go to the other sections and add the watermark again. That looks good too, but now go look at the first section you put the watermark on, and it’s gone! The process removes all watermarks from all other sections, and only inserts the watermark on the new section. Now this is getting dangerous when it comes to legal documents. You get the same issues when you use different first page footers within a section.

It’s very easy to create your own custom code for inserting and deleting bookmarks, and even use the existing built-in bookmarks in 2007/2010. Turns out the bookmarks you see are just auto-text entries, and it’s the name of the entries you see in the list. For example the Draft watermarks are auto-text entries “DRAFT 1” and “DRAFT 2”. So you just need some code to insert the appropriate auto-text into the document, so look no further…

Sub InsertWatermark(ByVal WatermarkAutoTextName As String)
  If Documents.Count > 0 Then
  Application.ScreenUpdating = False
‘ Store the current location in document
ActiveDocument.Bookmarks.Add(Range:=Selection.Range, Name:=“WatermarkTempBookmark”)
‘ Load all building block templates
‘ Find autotext entry first
Dim oTemplate As Template
Dim oAutoTextEntry As AutoTextEntry
Dim EntryFound As Boolean
Dim oSection As Section
Dim oRange As Range
EntryFound = False
For Each oTemplate In Templates
For Each oAutoTextEntry In oTemplate.AutoTextEntries
If LCase(oAutoTextEntry.Name) = LCase(WatermarkAutoTextName) Then
‘ Insert autotext in all headers in all sections of document
        For Each oSection In ActiveDocument.Sections
oRange = oSection.Headers(wdHeaderFooterPrimary).Range
oAutoTextEntry.Insert(rngRange, True)
oRange = oSection.Headers(wdHeaderFooterFirstPage).Range
oAutoTextEntry.Insert(rngRange, True)
oRange = oSection.Headers(wdHeaderFooterEvenPages).Range
oAutoTextEntry.Insert(rngRange, True)
Next oSection
EntryFound = True
Exit For
End If
Next oAutoTextEntry
If EntryFound Then Exit For
Next oTemplate
‘ Return to original place in document
If ActiveDocument.Bookmarks.Exists(“WatermarkTempBookmark”) Then
Selection.GoTo(What:=wdGoToBookmark, Name:=“WatermarkTempBookmark”)
End If
Application.ScreenUpdating = True
End If
End Sub

Now just setup a sub to call the above with the appropriate autotext name, and add a button and callback to call this sub. As an example, the following sub will insert the first DRAFT watermark – “DRAFT 1”.

Sub InsertDraftWatermark()
InsertWatermark(“DRAFT 1”)
End Sub

Now all you need is a routine to remove the watermarks. That’s the easy part. All the watermarks inserted by the default autotexts contain “PowerPlusWaterMarkObject” in the name – so we just need to check the name of the shape objects throughout the document and delete them.

Sub RemoveWatermarks()
‘ Removes all Word 2010 watermarks
On Error Resume Next

  If Documents.Count > 0 Then
Dim WatermarkShape As Shape
‘ Remove from body of document – the normal 2010 option inserts into the body
For Each WatermarkShape In ActiveDocument.Shapes
If InStr(1, WatermarkShape.Name, “PowerPlusWaterMarkObject”, vbTextCompare) = 1 Then
End If
‘ Remove from headers
Dim oSection As Section
For Each oSection In ActiveDocument.Sections
For Each WatermarkShape In oSection.Headers(wdHeaderFooterPrimary).Shapes
If InStr(1, WatermarkShape.Name, “PowerPlusWaterMarkObject”, vbTextCompare) = 1 Then
End If
For Each WatermarkShape In oSection.Headers(wdHeaderFooterFirstPage).Shapes
If InStr(1, WatermarkShape.Name, “PowerPlusWaterMarkObject”, vbTextCompare) = 1 Then
End If
For Each WatermarkShape In oSection.Headers(wdHeaderFooterEvenPages).Shapes
If InStr(1, WatermarkShape.Name, “PowerPlusWaterMarkObject”, vbTextCompare) = 1 Then
End If
Next oSection
End If
End Sub

So there you have it, code to insert and remove watermarks throughout the entire document, no matter how you setup your sections and headers. The code could probably be done a little better. Also there is the issue of creating custom watermarks. And then there’s the question of getting this functionality into the ribbon. If you need the answers to all those questions (and more) then get in touch with us. You might be surprised what we have hidden up our sleeves (just wish there were some descent cards up there – I still can’t manage a win at poker, or do a card trick that slightly impresses the kids)


Update on Monday, February 10, 2014 at 10:32PM

Just to let you all know that this issue has been fixed in Word 2013.

Our hands were tied recently when we had to develop a 32 bit web app due to the reliance on a 3rd party app that was 32 bit only.

We quickly worked out how to get the app running in 32 bit mode in IIS7 just by setting the “Enable 32-Bit Applications” setting within the application pool used for the app.

This worked great until we went to do this on a server running OWA 2010. After setting the application pool to run 32 bit apps, we still got an error:

Service Unavailable

HTTP Error 503. The service is unavailable.

And as an added bonus, the application pool was now stopped. Yippee – I guess that was 5 errors in less than 5 minutes!

A quick look in the Application event log showed the following error:

The Module DLL ‘C:\Program Files\Microsoft\Exchange Server\V14\Bin\kerbauth.dll’ could not be loaded due to a configuration problem. The current configuration only supports loading images built for a x86 processor architecture. The data field contains the error number. To learn more about this issue, including how to troubleshooting this kind of processor architecture mismatch error, see http://go.microsoft.com/fwlink/?LinkId=29349.

The Source was IIS-W3SVC-WP and the Event ID was 2282.

A bit of research pointed us in the direction of setting the kerbauth.dll to be 64 bit only in the applicationHost.config file for IIS (located in C:\Windows\System32\inetsrv\config). So we stopped IIS and edited the file. In the globalModules section, we found the line for kerbauth, and added the precondition=”bitness64” attribute as follows:

<add name=kerbauthimage=C:\Program Files\Microsoft\Exchange Server\V14\Bin\kerbauth.dllpreCondition=bitness64 />

We restarted IIS (and also the app pool!) and now the app showed the following error:

HTTP Error 500.0 – Internal Server Error

Calling LoadLibraryEx on ISAPI filter “C:\Program Files\Microsoft\Exchange Server\V14\ClientAccess\owa\auth\owaauth.dll” failed

So we applied the same theory again, and again for each dll that caused an issue – luckily for us there were only two – owaauth.dll and AirFilter.dll. Both were listed in the <isapiFilters> section of the applicationHost.config file:

<filter name=Exchange OWA Cookie Authentication ISAPI Filterpath=C:\Program Files\Microsoft\Exchange Server\V14\ClientAccess\owa\auth\owaauth.dllenabled=true preCondition=bitness64 />

<filter name=Exchange ActiveSync ISAPI Filterpath=C:\Program Files\Microsoft\Exchange Server\V14\ClientAccess\sync\bin\AirFilter.dllenabled=true preCondition=bitness64/>

We restarted IIS again and voila – a happy application, and OWA still worked to boot. Who says you need to run 32 bit apps on a separate server! Happy days…

Now I’ve just gotta get that song out of my head… “taking care of bitness and working overtime…” ;-)

Recently I was dealing with an interesting issue regarding the SplendidCRM marketing system.

Whenever the client sent emails out via the CRM, it would not de-duplicate the emails.  Therefore, if the recipient was on two target lists in the campaign they would receive the email twice. Not ideal really.

After much searching I could not find any settings in the CRM which offer the de-duplication of emails, so I decided to come up with my own solution.

After downloading the latest SplendidCRM community edition which comes with all the source code including SQL stored procedures, I dug through the code and found that the send email function was using the spCAMPAIGNS_SendEmail stored procedure.

I decided to update this stored procedure so that it marks any duplicate email as deleted when the campaign is sent, and now the recipients only receive the email once. I found this to be the most efficient and cost effective solution for our client.

Please click here to download the updated SQL query for the stored procedure.

Please note: Should you apply this updated stored procedure, please be aware that it supplied as is and applied at your own risk.  You should ensure adequate backups are in place and that you apply any appropriate testing for your environment.

We recently developed a web app for a client that allows their users to wake up their computer without knowing the MAC address – just their machine name. The app gets the MAC address and default gateway details from the client’s Microsoft SCCM database.

All was going well, until we found some machines that wouldn’t wake up. Further investigation revealed that it was only when machines had been shutdown via Windows 7 – ie if the machine had just gone to sleep, or had been powered off using the power button then it would wake up fine.

Before and after installing the Intel NIC driverTurns out those difficult machines were those using an Intel NIC and running the standard Microsoft driver included in Windows 7 (so basically 99.99% of the machines!)

After downloading and installing the latest drivers from Intel, a new Power Management tab appeared when configuring the NIC, and lo and behold, there’s a couple of extra settings relating to Wake On Lan that were disabled. Enabling the “Wake on Magic Packet from power off state” option magically fixed the problem (we enabled the other options while we were at it too).

Now the only problem is how to roll out the driver to all machines with these options by default. It sounds like it’s a setting in the NIC’s firmware that is controlling this (if the machine is powered off then it can’t be the driver?), so it would be interesting to reimage a machine after changing the setting and then use the original driver to see if the problem comes back. I guess we’ll see what happens…

Want to stop your installations being from an unknown publisher according to Window 7’s UAC?

Well, if you’ve got a code signing certificate, you’ll want to sign your MSI files. You can of course just sign your files manually using the signtool utility as follows:

signtool.exe sign /a “path to your msi

The location of signtool varies depending on which version of Visual Studio you have installed. You can do a search for it, or you can just run it via the “Visual Studio Command Prompt” shortcut in your start menu (under Microsoft Visual Studio/Visual Studio Tools)

Obviously that gets annoying pretty quickly if you’re compiling it in Visual Studio all the time, so instead just add the call to signtool as a Post Build script within your Setup project:

“C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\signtool.exe” sign /a /d “My Application” “$(BuiltOuputPath)”

Make sure the path to signtool is correct. Also, change “My Application” to the name of your application – this appears as the program name in the UAC prompt that appears. If you don’t set it to a value, the default will be the name if the MSI that Windows Installer assigns (which you can assume will be some ugly hex number)

You can also add a link to additional information about your product by using the /du parameter with signtool – but I’ll leave that to you to work out…

Have you ever logged in to Vista or Windows 7, and after entering your password all you end up with is a black screen with only the mouse pointer appearing? Don’t worry – your machine’s probably not screwed completely – to prove it, hit the Shift key five times and you should see some sign of life. You can even use that sign of life to get access to most things on your machine should you feel so inclined.

Well we’ve suffered it a few too many times on some of our machines, and after cursing, pulling our hair out, lots of research on the web, and even upgrading one machine from Vista to Windows 7, we finally came across what is a pretty simple fix which has worked every time.

Turns out for us it’s always been due to a problem with the event logs – and clearing them out fixes the issue.

So how do you clear out your event logs?  Just boot into Safe Mode (I’m assuming you know how to do that – that’s the “press the F8 key as your machine starts up” thingy), log in as normal, then go to the event viewer (from the start menu and right click on “Computer”, select Manage, then click on the Event Viewer option from System Tools)  Next expand the Event Viewer option, then expand both the Windows Logs and Applications and Services Logs options, then on each log (like Application, Security etc), right click on it and select Clear Log… I then select the Clear option (who wants to save the logs anyway?)  Now reboot again and voila – you should now have a working machine.

Well that works for us…let us know how you get along.

Oh, and Microsoft, can you go and fix your operating system – it shouldn’t die like this because of some simple corruption – how about an error message and a simple prompt to reset any log that’s got problems?

Now as to what is causing the problem – well it’s probably the antivirus software or something like that. I’d do some more investigation but…

© Copyright - Mosmar