VBA: Create Slide for every Picture in a Folder

By Craig November 23rd, 2011, under Microsoft Office

This short script runs in PowerPoint VBA. It looks in a given folder for any image and creates a new slide for that image. Once the image has been inserted it determines if the image is portrait or landscape and then resizes the picture, keeping the proportions, to fit the given slide layout as best it can.  

Option Explicit
Sub CreatePictureSlidesByFolder()
    'Define Variables
    Dim PictureFolder As String
    Dim CurrentSlide As Slide
    Dim CurrentFile As String
    Dim CurrentFileFullName As String
    Dim AllowedExtensions() As Variant
   
    'Set the Path to the folder of pictures
    PictureFolder = "\\data\staffdata\ctolley\My Pictures\Sample Pictures"
   
    'Check that the Picture folder path has a trailing \
    If Right(PictureFolder, 1) <> "\" Then PictureFolder = PictureFolder & "\"
   
    'Define the allowed picture extensions
    AllowedExtensions = Array("jpg", "png", "bmp")
   
    'Check that 1 slide exists in the presentation
    If ActivePresentation.Slides.Count = 0 Then
        ActivePresentation.Slides.Add 1, ppLayoutTitle
        ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Text = PictureFolder
    End If
   
    'Get the files in the folder
    CurrentFile = Dir(PictureFolder)
   
    While CurrentFile <> ""
   
    'Check that the file extension is allowed
    If IsStringInArray(GetFileExtension(CurrentFile), AllowedExtensions) Then
   
        'Make the full file name
        CurrentFileFullName = PictureFolder & CurrentFile
   
        'Add a new slide to the presentation
        Set CurrentSlide = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
       
        'Add the picture to the presentation
        With CurrentSlide.Shapes.AddPicture(CurrentFileFullName, msoFalse, msoTrue, 0, 0)
       
            'Check if the picture is landscape or portrait
           
            If .Width > .Height Then
                'Landscape
                .Width = ActivePresentation.PageSetup.SlideWidth
                .Left = 0
                .Top = (ActivePresentation.PageSetup.SlideHeight - .Height) / 2
           
            Else
                'Portrait
                .Height = ActivePresentation.PageSetup.SlideHeight
                .Left = (ActivePresentation.PageSetup.SlideWidth - .Width) / 2
                .Top = 0
            End If
           
        End With
       
    End If
           
    'Clear the current file
    CurrentFile = Dir
   
    Wend
End Sub
Public Function GetFileExtension(TheFilePath As String) As String
    'Separates the file extension from the file name and returns it.
    Dim FileParts() As String
    FileParts = Split(TheFilePath, ".")
    GetFileExtension = FileParts(UBound(FileParts))
End Function
Public Function IsStringInArray(TheString As String, TheArray() As Variant) As Boolean
    'Determines if the passed string is in the passed array.
    Dim ArrIdx As Integer
    For ArrIdx = LBound(TheArray) To UBound(TheArray)
        If TheString Like TheArray(ArrIdx) Then IsStringInArray = True
    Next ArrIdx
End Function

Resizing a Dynamic System Partition on Windows 2003 – for Free.

By Craig October 25th, 2011, under Server 2003

Ok. I have a server running Windows Small Business Server 2003. Back in the day when it was set up I naively had only a 20gb System volume, on a dynamic disk, mirrored. Unfortunately that ran out of space, so I set about extending the partition.

Windows Disk Management and Diskpart in Windows 2003 don’t allow you to extend the volume with the O/S on it. This limitation meant that I went to a tried, tested and trusted friend in GParted. Unfortunately, GParted also cannot extend volumes on dynamic disks created with the Windows LVM.

After an hour of trying to find a way to do it, I nearly ended up paying for professional tools (which do exist if you want the support and backup). I then remembered that Windows 2008 does allow you to resize the system partition.

This means that the Windows 2008 version of DiskPart can perform this function, and is included in Windows PE 3.

So, grab a copy of the Windows Automated Installation Kit from here: http://www.microsoft.com/download/en/details.aspx?id=5753 create your Windows PE 3.0 CD and boot. Instructions for creating the CD or UFD are here: http://technet.microsoft.com/en-us/library/cc749311(WS.10).aspx

Full instructions for the Windows 2008 version of DiskPart can be found here: http://technet.microsoft.com/en-us/library/cc770877(WS.10).aspx

Remember to always create a backup though.

1 person found this post useful.

Data Protection – Just Can’t Get Enough

By Craig September 9th, 2011, under General Stuff

Ok, not strictly IT here, but important none the less.

Data Protection is big, and whilst you personally cannot be prosecuted for breaching the Act, your company can be fined.

Just had a check up on the Information Commissioners Office (ICO) – and found some new resources.

Th!nk Privacy is a campaign developed between the ICO and Blue Goose. It is a collectionof posters and resources which can be used to reinforce your Data Protection training. Use it on routine security sweeps and compliance should increase.

Combine this with the ICO’s offering of free resources for organisations which they can use to protect themselves and provide training.

All this provides you with no reason to protect personal information and comply with the Data Protection Act. The weakest link tends to be staff, so use this to reduce that risk.

Th!nk Privacy: http://www.ico.gov.uk/news/current_topics/think_privacy.aspx

ICO Publications: https://www.ico.gov.uk/tools_and_resources/request_publications.aspx

Disable ‘Automatically detect settings’ in Internet Explorer

By Craig August 30th, 2011, under Internet Security, VBScript

This script allows you to turn off (or on) the ‘Automatically Detect Settings’ check box in Internet Explorer.

I have not been able to find a way which guarantees that this will not be checked. You can set a Group Policy into Internet Explorer Preference Mode, but if a user later changes it, then it will not change back. If you Disable Changing IE Proxy Settings, then the Preference Mode Setting seems not to work.

I have set this script to run at logon, as part of our general login script. It only modifies that one setting, no others. It reads the entire of the binary value, modifies the one binary value that needs changing and then writes back the entire value.

Option Explicit
On Error Resume Next
'Create a constant for the HKEY_CURRENT_USER object
Const HKCU = &H80000001
'Define variables
Dim strComputer
Dim strRegistryKey
Dim objRegistry
Dim strRegistryValue
DIm binValue
strComputer = "."
strRegistryKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
strRegistryValue = "DefaultConnectionSettings"
'Connect to the Registry
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
'Retrieve the current settings.
objRegistry.GetBinaryValue HKCU, strRegistryKey, strRegistryValue, binValue
'Change the 'Automatically detect settings' box to unticked
binValue(8) = 05
'binValue(8) = 13 - Enable this line to check the box instead of uncheck
'Save the changes
objRegistry.SetBinaryValue HKCU, strRegistryKey, strRegistryValue, binValue

Windows PE 3.0: IRQL_NOT_LESS_OR_EQUAL

By Craig July 27th, 2011, under Microsoft Windows

Have been working with Windows PE 3.0 to create an automated bootable USB and CD that boots a machine, partitions the disk, applies an image and copies some files to create a ThinStation thin client.

Whenever we booted our target machines, we got the following error:

IRQL_NOT_LESS_OR_EQUAL - 0x0000000A

Windows PE 3.0 has a minimum requirement of 256mb of  useable RAM. The machines that we were using had 256mb of RAM total, and were using Shared Memory for the Graphics card – reducing the actual available RAM to 224mb, causing the boot to fail.

The limitations of Windows PE are listed through the link below.  This link takes you to the details for Windows PE 2.0, but as far as I can find the limitations and the requirements are the same.

http://technet.microsoft.com/en-us/library/cc507857.aspx

1 person found this post useful.

Rack Design & Cable Management

By Craig July 5th, 2011, under General Stuff, Networking

A not-too-detailed but quality post highlighting some of the important factors of rack design and layout.

http://www.bcs.org/content/conBlogPost/1891?src=ebcsbrunch

 

3 people found this post useful.

VBA: Create PowerPoint Slide for Each Row in Excel Workbook

By Craig June 8th, 2011, under Office 2010

This may seem like a really weird thing to want to do. Imagine this though: You want a presentation to show off the names of a lot of students on a constant loop at a kiosk, and you don’t want to have to retype the names. VBA to the rescue.

This little snippet of code will do the following:

  1. Open a given Excel Document
  2. For Each used row in column A of sheet 1, create a copy the first slide in the presentation.
  3. Change the text of the first text box to the content of that cell

Easy. Here it is:

Sub CreateSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As New Excel.Workbook
Set OWB = Excel.Application.Workbooks.Open("C:\list.xlsx")
'Grab the first Worksheet in the Workbook
Dim WS As Excel.Worksheet
Set WS = OWB.Worksheets(1)
'Loop through each used row in Column A
For i = 1 To WS.Range("A65536").End(xlUp).Row
    'Copy the first slide and paste at the end of the presentation
    ActivePresentation.Slides(1).Copy
    ActivePresentation.Slides.Paste (ActivePresentation.Slides.Count + 1)
   
    'Change the text of the first text box on the slide.
    ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes(1).TextFrame.TextRange.Text = WS.Cells(i, 1).Value
Next
End Sub

Paste this into a new module inside your PowerPoint presentation. You will need to add in a reference to Microsoft Excel Objects (Tools -> References). Change the name and location of the Excel file that you want to use.

If you set up the first slide exactly as you want it before running the macro, then the same formats and layout will be copied too. Alternatively use Slide Masters to set up all the slides after they have been created.

4 people found this post useful.

Could Not Open file.doc from SharePoint Server 2010

By Craig June 6th, 2011, under Microsoft Office, Office 2010, SharePoint

I have found a couple of solutions to this on the web, but nothing like this.

We have SharePoint Server 2010 and Office 2010. I was browsing to a file located on My Site, but other documents . Excel or Word would open and then i would be told:

Could not open filename.doc

You would then click ok, the message disappeared and you would not have an open document.

In our case, it was nothing to do with IE security settings, or Office 2010 protected mode.

We had been trialling SharePoint WorkSpace with a copy f my My Site attached so that I could work on my MySite documents at home. The copy that was stored on my computer had not been updated as I had disabled the option to start SharePoint WorkSpace after I was happy that it would work.

The fix for me therefore was to either delete the local sync copy or to have it update the local copy.

Back to be able to get my work.

1 person found this post useful.

TMG & ISA Tools

By Craig May 23rd, 2011, under Internet Security

Just a quick plug for Jim Harrison here, who for the third time this month has made my life easier by either collating or producing an array of useful tools for ISA and TMG.

Take a peek at http://www.isatools.org/

Also got up to date information on ISA and TMG releases. Definitely one to bookmark.

Combining SharePoint 2010 and Windows Media Services

By Craig May 20th, 2011, under SharePoint

This may already be covered elsewhere, but I am writing it up anyway.

We use SharePoint 2010. We also have a lot of video content, shared amongst many staff, of which presently there are multiple copies of the content scattered around the network. The aim was to remove all these duplicate copies of ‘static’ data, combine them together and add them to a searchable database.

We wanted to use Windows Media Services to allow the media to be streamed to the clients too, so multiple people can watch and share the file simultaneously.

We needed a site which allowed users to upload files to the Windows Media Services Server, but also create the necessary URL links inside SharePoint. If it was too complicated people wouldn’t use it, and us in ICT did not want to spend the next few weeks doing it all for them.

This caused the birth of the Streaming Media Upload site. This site uses the following ideas to simplify making streaming media available.

  1. User browses to the site. They select the file that they want to upload, and enter basic details such as the Title, Author, Information about the clip and the Copyright Holder.
  2. The user also selects the SharePoint List to add the clip to.
  3. The user selects upload.
  4. The media file is uploaded and saved in the Windows Media Services Content Folder
  5. An ASX file is created with a link to the clip, along with the clip information specified to the user. This ASX file is saved in a web directory
  6. A new URL List Item is created in the SharePoint list which refers back to the ASX file.

In this way, SharePoint is not filled up with video content, which would bloat the database, but full details of the videos are stored in SharePoint which can be searched upon.

Full details of how we set up this system are included on the Windows Media Services Upload Site page, at the top.