2011-09-27

Microsoft Word Macro: Convert Word-files to PDF-files

Microsoft Word Macro

This post comes out of me helping a colleague with a quick macro, for Microsoft Office Word, that he needed to speed up service towards a customer.

I simply recorded a macro while converting one Word-file into a PDF-file and then Googled for some code to access files on disc and put it all together in a loop.

Sub ConvertWordsToPdfs()

    Dim directory As String    
    directory = "C:\Wordup"
  
    Dim fso, newFile, folder, files
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    Set folder = fso.GetFolder(directory)
    Set files = folder.files
    
    For Each file In files

        Dim newName As String
        newName = Replace(file.Path, ".doc", ".pdf")
                
        Documents.Open FileName:=file.Path, _
            ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
            PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
            WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
            wdOpenFormatAuto, XMLTransform:=""
            
        ActiveDocument.ExportAsFixedFormat OutputFileName:=newName, _
            ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
            wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
            Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
            CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
            BitmapMissingFonts:=True, UseISO19005_1:=False
        
        ActiveDocument.Close
      
    Next

End Sub

I guess I won't update or tune this macro a lot, but you can find this macro as a Github Gist as well.

2011-05-18

Add Facebook Like, Twitter Tweet and Other Social Links to Your Blog

If you want people to be able to quickly and easily link to your blog-posts or pages in general you can take some shortcuts to get that functionality by using AddThis.

There are several ways to include buttons from AddThis to your page, but for standard functionality with a good overview I would say point to using regular HTML with some automatic JavaScript-magic happening in the background.

The basic code looks like this:

<div class="addthis_toolbox addthis_default_style">
    <a class="addthis_button_facebook"></a>
    <a class="addthis_button_tweet"></a>
    <a class="addthis_button_email"></a>
</div>

There is a very well documented and detailed API Reference on AddThis' website.

Customizing

There are some additional classes you can add to the link-tags to make specialized customization to the buttons. If you add addthis_32x32_style the icon will become larger and stick out more. It could be used on the more popular social sharing services.

<div class="addthis_toolbox addthis_default_style">
    <a class="addthis_button_facebook addthis_32x32_style"></a>
    <a class="addthis_button_twitter addthis_32x32_style"></a>
    <a class="addthis_button_digg addthis_32x32_style"></a>
    <a class="addthis_button_delicious addthis_32x32_style"></a>
    <a class="addthis_button_google"></a>
    <a class="addthis_button_googlebuzz"></a>
    <a class="addthis_button_blogger"></a>
    <a class="addthis_button_tumblr"></a>
    <a class="addthis_button_posterous"></a>
</div>

Which produces a result that looks like this:

With this code Facebook, Twitter, Digg and Delicious are twice the size of the other ones.

AddThis has an extremely long list of supported sharing services supported.

2011-04-27

Language Localization with Google Maps API

Google Maps

When you include a Google Maps to your website via the Google Maps JavaScript API uses the browser's set preferred language to display the texts. Sometimes this doesn't turned out as planned and you want to be able to override this with your own choice.

Changing language is done with an additional argument when referencing the script-file. The argument used is language.

<script type="text/javascript"
    src="http://maps.google.com/maps/api/js?sensor=false&language=ja">

There is of course a reference to the supported languages and their language codes.

Region Localization

To set the language of the names of the countries, cities and other places, you can use the Region Localization.

2011-04-18

Javascript: Timeout on a Textbox using jQuery

jQuery

Here is a quick post about how to use a JavaScript-timer to only execute a textbox's functionality after a certain amount of time.

Worth noticing in the code is that we handle a key-press on the Enter-button instantly, while otherwise we only execute the functionality after the user left the keyboard alone for 0,5 seconds.

var filterTimeoutId = 0;

var textboxFunction = function() {
   // The function the textbox should perform
};

$('input#TextBox').keypress(function (e) {
    if (e.which === 13) { // Enter-key
        e.preventDefault(); // Prevent page postback
        clearTimeout(filterTimeoutId);

        textboxFunction();
        return;
    }

    clearTimeout(filterTimeoutId);
    var timeout = 500; // Timeout in milliseconds
    filterTimeoutId = setTimeout(textboxFunction, timeout);
});