IsFile()/IsFolder() - Does file/folder exist?
VBA UDF (User Defined Function) to determine if a file or folder exists, e.g.
If IsFile(""C:\test.txt"") Then Msgbox "File exists" Else Msgbox "File does NOT exist." End If
Welcome to the portion of my website where I share and store information or tools about Microsoft Access and Excel. Hope you find some of it interesting or helpful!
If you're totally new to using Microsoft Access, I recommend reading this article to help get you started.
If you have any questions or suggestions for the articles on the website, feel free to post in the forums. I can't promise my response will be quick, but I will try my best to respond to all forums posts.
Sincerely,
Azli
As an Amazon Associate I earn from qualifying purchases.
VBA UDF (User Defined Function) to determine if a file or folder exists, e.g.
If IsFile(""C:\test.txt"") Then Msgbox "File exists" Else Msgbox "File does NOT exist." End If
If sheets in a workbook have different DPI values (dot per inch, i.e. affects print resolution / quality) and you try to print them all at once to a PDF printer, Excel will print them as separate files. This code will set the DPI for ALL sheets to a single DPI value, i.e. 1200 dpi.
Here is a simple example of creating a table using DAO. Be sure that your DAO reference is set.
You can also use SQL to create a table. I've got an example here.
If you wanted to you could use DAO to execute that SQL or even DoCmd.RunSQL.
I've also got some simple code (DAO and ADO) to manipulating recordsets, which you will need to know how to do in order to add new records to a table (see here). Again, you could use an SQL statement (i.e. INSERT INTO) from VBA but I think using a DAO recordset is easier to code an understand.
Be sure that you execute the .Update statement after adding a new record (using. AddNew) and creating the values for the fields. Remember if you use the field number, that .Field is 0-indexed; i.e. the first field is .Field(0) not .Field(1).
Sub CreateNewTblDef() On Error GoTo ErrMsg: Dim db As DAO.Database Dim tdf As DAO.TableDef 'Specify database to add file to 'We will use the current file for this example Set db = CurrentDb() 'Create a new TableDef object Set tdfNew = db.CreateTableDef("tblNew") With tdfNew 'Create fields and append (i.e. add) them 'to the new TableDef object. .Fields.Append .CreateField("strText", dbText) .Fields.Append .CreateField("memMemo", dbMemo) .Fields.Append .CreateField("lngLong", dbLong) .Fields.Append .CreateField("dblDouble", dbDouble) .Fields.Append .CreateField("blnBoolean", dbBoolean) End With 'Append the new table only after adding the fields db.TableDefs.Append tdfNew db.Close ExitHere: Exit Sub ErrMsg: 'Handle Errors MsgBox "Uh-oh! An error occured!" & vbNewLine & vbNewLine & _ "Error Number: " & Err.Number & vbNewLine & _ "Error Description: " & Err.Description, vbCritical Resume ExitHere: End Sub
You can manually follow the dependency chain of a formula, i.e. see how cell formulas flow or progress through a sheet, using a combination of CTRL, SHIFT, and the two square brackets, i.e. [ & ]. Let's say you have the following on a sheet in Excel:
A | Formula | |
---|---|---|
1 | 1 | 1 |
2 | 2 | =A1+1 |
3 | 2 | =A2 |
4 | 4 | =A2*2 |
If you select cell A1, then press CTRL + ], cell A2 will be selected. If you press CTRL + ] again, the range A3:A4 will now be selected since both of those are dependent on B2.
If you select A4 and press CTRL + SHIFT + ], the range A1:A2 will now be selected since A4 relies on them, on A2 directly and A1 indirectly (since A2 is dependent on A1). If you go back and re-select cell A1, then press CTRL + SHIFT + ], cell A2:A4 will be selected, because those all rely on A1 either directly or indirectly.