Archive for September, 2011

September 16th, 2011

VBA – Determine if a Folder/Directory Exists or Not

It can often come handy to be able to quick determine if a Folder/Directory exists or not. Below is a function I created some time ago to do exactly that.

'---------------------------------------------------------------------------------------
' Procedure : FolderExist
' DateTime  : 2009-Oct-02 13:51
' Author    : CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Test for the existance of a Folder/Directory
' Copyright : The following may be altered and reused as you wish so long as the
'             copyright notice is left unchanged (including Author, Website and
'             Copyright).  It may not be sold/resold or reposted on other sites (links
'             back to this site are allowed).
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sFolder - Full path of the folder to be tested for
'---------------------------------------------------------------------------------------
Function FolderExist(sFolder As String) As Boolean
On Error GoTo Error_Handler
 
    If sFolder = vbNullString Then GoTo Error_Handler_Exit
    If Dir(sFolder, vbDirectory) <> vbNullString Then
        FolderExist = True
    End If
 
Error_Handler_Exit:
    On Error Resume Next
    Exit Function
 
Error_Handler:
    If Err.Number <> 52 Then
        MsgBox "The following error has occured" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: FolderExist" & vbCrLf & _
           "Error Description: " & Err.Description, vbCritical, "An Error has Occured"
    End If
    Resume Error_Handler_Exit
End Function

Share and Enjoy

  • Google Plus
  • Facebook
  • LinkedIn
  • Twitter
  • Email
  • Print
September 15th, 2011

VBA – Create Directory Structure/Create Multiple Directories/Create Nested Directories

One of he most common methods for creating directories/folders in VBA is to use the MkDir statement. For instance:

MkDir "C:\databases\"

One quickly learns the limitations of this technique the minute they have to create a directory structure with multiple sub-folders. MkDir can only create 1 directory at a time and cannot create a sub-directory. Hence, assuming that C:\databases does not already exist, the following would not work and will return an error!

MkDir "C:\databases\msaccess\"

If you absolutely want to create such a structure using the MkDir statement you’d have to do so using 2 MkDir statement. For instance:

MkDir "C:\databases\"
MkDir "C:\databases\msaccess\"

Now if you need to merely create 1 or 2 sub-folder MkDir may still be acceptable, but there are cases where this is simply impracticle and another solution needs to be found. Well, I found two possible solutions!

One possible approach can be found at Creating Nested Directories.

The second I found searching through the net and I no longer know the original source of the code (if someone knows e-mail me and I will put credit where it is due). It is a simple API which can create multiple directories in 1 call.

Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal lpPath As String) As Long
 
Public Sub MakeFullDir(strPath As String)
    If Right(strPath, 1) <> "\" Then strPath = strPath & "\" 'Optional depending upon intent
    MakeSureDirectoryPathExists strPath
End Sub

Another possible solution, if someone wanted to tinker a little would be to merely parse the path into it’s directories and the using the DIR statement evaluate and create the directories where need be. Shouldn’t be that hard, but I haven’t taken the time to do this (maybe one day I will and will update this post then).

Okay, so it bothered me and I had to quickly put something together to stop my brain from churning! Below is what I pieced together rapidly. It is missing proper variable definitions (DIM statements) and error handling, but from my very brief testing, it does appear to work and doesn’t require any APIs! 100% VBA.

Public Sub MyMkDir(sPath As String)
    Dim iStart          As Integer
    Dim aDirs           As Variant
    Dim sCurDir         As String
    Dim i               As Integer
 
    If sPath <> "" Then
        aDirs = Split(sPath, "\")
        If Left(sPath, 2) = "\\" Then
            iStart = 3
        Else
            iStart = 1
        End If
 
        sCurDir = Left(sPath, InStr(iStart, sPath, "\"))
 
        For i = iStart To UBound(aDirs)
            sCurDir = sCurDir & aDirs(i) & "\"
            If Dir(sCurDir, vbDirectory) = vbNullString Then
                MkDir sCurDir
            End If
        Next i
    End If
End Sub

As you can see, there are numerous way to handles this issue. Hopefully this helped answer a question for a few of you out there!

Share and Enjoy

  • Google Plus
  • Facebook
  • LinkedIn
  • Twitter
  • Email
  • Print
September 9th, 2011

Brother HL-2270DW Laser Printer – Review

So a couple months ago, I finally broke down and bought a new printer since Windows 7 x64 didn’t support my existing printer. After perusing the weekly flyers and speaking with a good friend, I ended up purchasing the Brother HL-2270DW. Below are my thoughts on the printer after several months of usage.

 

Pros

  • Extremely faster printer (up to 27 page per minute)
  • Wakes up fast from sleep mode
  • Decent size paper tray (250 sheets)
  • Easy duplex printing without the need of manual intervention on the part of the user
  • Relatively cheap toner (when compared to my previous printer – about half the cost for the same yield)
  • Good quality printing (from my perspective)

 

Cons

  • No USB cable supplied (although it is a wireless printer, it is recommended for the installtion)
  • I found the installation process ‘confusing’ referring to terms the average user will not know
  • Envelop printing is very poor as it crumples the envelop (unacceptable for business purposes)

In conclusion, I like this printer, but am disappointed with the envelop print quality. If I had to give it a grade it would be 88/100. All in all, it is a good printer for individual and small business use.

Share and Enjoy

  • Google Plus
  • Facebook
  • LinkedIn
  • Twitter
  • Email
  • Print
September 1st, 2011

SEO Companies – SEO Optimization Service E-mails

If you own a website, you undoubtibly have received beautiful SPAM e-mails from various sources offering you their Search Engine Optimization (SEO) services. Now the following points may be obvious to some, but I thought I’d put them black on white for people who are new to the field, or are simply not aware of a few things in the www.

so you’ve received and e-mail such as (just a few examples)

We offer quality Search Engine Optimization / SEO Services and Internet Marketing Solutions. Our dedicated team of SEO Professionals ensures Top 10 search engine rankings. Our SEO Processes are designed in view of the SEO guidelines, and white hat SEO techniques are strictly followed to ensure that our clients from world over get the best SEO services. Please reply to this email so we can send you more details.

We will optimize your site to increase its rankings with major search engines. This will drive targeted online users to your site, as well as attract new users through the use of relevant keywords and phrases. Not only will we help you gain those higher rankings, but maintain your status through continual management and support. Please reply to this email so we can send you more details.

We noticed that you are not at the top of the search engines for a number of your key terms. We have helped companies similar to yours to achieve top organic rankings. Please reply to this message and we will prepare a special proposal for you, to show you how we can achieve similar results for you.

We are interested to increase traffic to your website, please get back to us in order to discuss the possibility in further detail.

We strongly believe that we have an excellent opportunity to increase the number of visitors to your website through our white-hat SEO services. Please simply reply to this message and we will be delighted to send you further information.

Search Engine Marketing will increase your company’s online presence through comprehensive online marketing campaigns, targeted search engine optimization, and highly managed internet marketing promotions. A search engine marketing campaign will encompass several procedures and factors to make it successful. Please reply to this email so we can send you more details.

We are a leading India based SEO company providing the best search engine optimization services. We act as your business partner and helps you reach your business goals. We promote websites no matter who you are – a huge company with thousands of employees, a small business or a professional who offers professional / consulting services. Let us know if you are interested and we will get back to you with more details.

Hello,

Greetings for the day!

I am xxxxxxx and I am contacting you after looking at your website- .

We are a Leading Indian Based SEO & Web Development Company and one of the very few company which offer organic SEO services with a full range of supporting services such as one way themed text links, blog submissions, directory submissions, article writing and postings, etc.

We are a team of 50+ professionals which includes 18 full time SEO experts. We are proud to inform you that our team handled 100+ SEO projects and obtained 40000+ manually built links in the past 1 year.

We will be glad to assist you with offering our services. Please let me know your Interest so that we can tell you more about Our Services.

Thanks
—————-
xxxxxxx xxxxxxxxxx
Online Marketing Consultant

Now there are a couple reasons why I would never deal with any of these companies:

  1. Firsty, they sent me SPAM!
  2. If I can’t be found on search engines, then how did they find me in the first place?
  3. They always use gmail, hotmail, live e-mail accounts. If they truly were a reputable company they would use their own corporate e-mail address. For me they represent fly by night companies that I would avoid at all cost.
  4. Similarily, in many casess, the e-mail address name does not match the sign-off name in the e-mail. Make me wonder?!
  5. Why hire a company to do what you can do yourself? SEO is very basic and there are no tricks that they possess that you cannot do yourself with a little time.
  6. Most importantly, any company that promises specific results I would avoid at all costs! No one can garantee where you will show up on any search engine since the equations behind indexing are private and always changing. A SEO consultant can say they will optimize your site, and should be able to improve your ranking, but to say you will end up on the 1st page is just ridiculous!

Also, please remember that you can’t be at the top of search engine searches for every keyword! So anyone can always claim that you are not at the top of search engine ranking for some keyword. You have to concentrate your efforts on a select group of keywords and work your site around the keywords you have chosen.

Another important thing to note about SEO is that it is an on-going process. There is always more that can be done. So it is important to fix a realistic goal and aim for that. Once you have done your SEO, you should then review your site statistics for a couple week or months, and then define a new attack plan.

At the end of the day though, if you want to get someone to do some SEO for you that is fine, but find yourself a web developer through your network, yellow pages, the person that developed your site. Then validate there abilities by asking for examples and references (anyone can claim to be a SEO expert). Just stay away from the SPAM, unsolicited SEO as they are questionable (refer to the list above).

Share and Enjoy

  • Google Plus
  • Facebook
  • LinkedIn
  • Twitter
  • Email
  • Print