How to check whether certain sheets exist or not in Excel-VBA? [duplicate]

Although (unfortunately) such method is not available, we can create our own function to check this.. Hope the code below fits your needs. Edit1: Added also delete statement… Sub test() If CheckSheet(Sheets(3).Name) then Application.DisplayAlerts = False Sheets(Sheets(3).Name).Delete Application.DisplayAlerts = True End If End Sub The solution I’d go for… Function CheckSheet(ByVal sSheetName As String) As … Read more

Reading Web Pages using Excel VBA

Coming from Excel 2003, yes this is possible – you may use the SHDocVw.InternetExplorer and MSHTML.HTMLDocument objects to call a web page, gain control over and interact with the DOM object. After creating references to Microsoft HTML Object Library (…\system32\MSHTML.TLB) and Microsoft Internet Control (…\system32\ieframe.dll) you can play with the following example: Sub Test() Dim … Read more

Excel VBA wildcard search

You can use Like operator (case-sensitive): Private Sub search_Click() For firstloop = 3 To 10 If Range(“G” & firstloop).Text Like name.Text & “*” Then MsgBox “Found!” Exit Sub Else MsgBox “NOT FOUND” End If Next End Sub for case-insensitive search use: If UCase(Range(“G” & firstloop).Text) Like UCase(name.Text) & “*” Then Also if you want to … Read more

VBA Function argument list select

This is what is known as an enumeration. Here is a quick example: Public Enum DayOfWeek Monday = 1 Tuesday = 2 Wednesday = 3 Thursday = 4 Friday = 5 Saturday = 6 Sunday = 7 End Enum Public Function GetDrinkSpecial(day As DayOfWeek) As String Select Case day Case DayOfWeek.Monday GetDrinkSpecial = “$1 Tap … Read more

OpenXml and Date format in Excel cell

This blog helped me: http://polymathprogrammer.com/2009/11/09/how-to-create-stylesheet-in-excel-open-xml/ My problem was that I wanted to add NumberingFormats to the stylesheet rather than adding a new stylesheet altogether. If you want to to that, use Stylesheet.InsertAt<NumberingFormats>(new NumberingFormats(), 0); rather than Stylesheet.AppendChild<NumberingFormats>(new NumberingFormats(), 0); surprise, order counts..

Excel 2007 automation on top of a Windows Server 2008 x64

The solution is really simple. The msdn forum thread can be found here To make a long story short I’m posting the solution here, credit goes to H Ogawa This solution is … ・Windows 2008 Server x64 Please make this folder. C:\Windows\SysWOW64\config\systemprofile\Desktop ・Windows 2008 Server x86 Please make this folder. C:\Windows\System32\config\systemprofile\Desktop …instead of dcomcnfg.exe. This … Read more