Archive

Posts Tagged ‘vba’

Change MS Access application title and icon using VBA

December 15th, 2009 No comments

Here is a code to change MS Access application title and icon using VBA. This code also sets the application icon as form and report default icon.

Dim db As Database
Set db = CurrentDb
db.Properties("AppIcon").Value = CurrentProject.Path & "\Bee.ico"
db.Properties("AppTitle").Value = msgMainTitle
db.Properties("UseAppIconForFrmRpt").Value = True
Application.RefreshTitleBar

Click here for list of all properties exposed by CurrentDB.Properties().

Categories: MS Access Tags: , ,

ADODB Command.Execute does not return error for RAISERROR

December 4th, 2008 No comments

Description:

I was executing a stored proc which would halt its execution using RAISERROR. When I tried to run the stored proc in Query Analyzer it worked fine and gave me error but in VBA it couldn’t halt the execution and continued to the next statement. Read more…

Categories: MS Access Tags: , , ,

MS Word: Remove watermark from all Word pages using VBA

March 28th, 2008 6 comments

You can create watermark in MS Word document by going to Format Menu > Background > Printed Watermarks… Here you will be able to set Text Watermark in each page. Now if you want to remove the watermark from all pages, use the following VBA script.

   Dim section As Word.section
   Dim pheadertype As Long
   Dim hdr As Range
   Dim sp As Shape
   Dim str As String
   For Each section In ActiveDocument.Sections
      With section
         Set hdr = .Headers(wdHeaderFooterFirstPage).Range
         For Each sp In hdr.ShapeRange
            str = sp.Name
            If InStr(str, "PowerPlusWaterMarkObject") > 0 Then
               sp.Visible = msoFalse
             End If
          Next
          Set hdr = .Headers(wdHeaderFooterPrimary).Range
          For Each sp In hdr.ShapeRange
             str = sp.Name
             If InStr(str, "PowerPlusWaterMarkObject") > 0 Then
                 sp.Visible = msoFalse
             End If
           Next
       End With
    Next