Lesson 1.10 – Working With Files

You need to be logged in to view this content. Please login or become a member.

<<  Prev   |   Index   |   Next  >>

Description

Need your macro to interact with every file in a specific directory? Create a directory? Copy, move, or delete a file? It’s all here.

Notes

The code that browses for a folder, which I copied from an external web site, does not work on 64 bit systems. Please use the code in the “Homework” and “Lesson Files” links below, which I have updated to work with 64 bit systems.

An alternative method for creating an open file dialog is to use Common Dialog controls. To do this you will need to right click on your toolbox and choose “Additional Control”. Then browse for Microsoft Common Dialog Control, version 6.0. Click the X to the left of the name and hit OK. Now you have the common dialog control available to you. Drag it onto your form but do not try to resize it. It will not actually be visible on your form, but now you can use the methods and properties for that control. For example, if the control is called “CommonDialog1” then you could create a dialog box to locate a file using the following:

CommonDialog1.ShowOpen

You can modify the selection filter using the Filter property.

Lesson Files

Lesson 1.10 start code
Lesson 1.10 code

Homework

Lesson 1.10 homework solution

2 Comments

  1. pranjal

    Hi Keith,

    After copying the ‘Browse For Folder’ code and pasting that in the Solidworks vb Module, it is showing the ‘Complie Error’ as ‘The code in this project must be updated for use on 64-bit systems. Please review and update. Declare statements and then mark with the PtrSafe attribute.’

    • Please use the code provided in the “Lesson Files” and “Homework” links above the comments. This code has been updated to work with 64 bit. You are correct that the code shown at that web site does not work on 64 bit systems. I will also note this in the video notes.

Questions and Comments

You must be logged in to post a comment.