PHP Data Recovery
Links

Code, Visual Basic, VB Excel, Electronic Surplus Parts, Electronic Circuits, Schematics, Etc.

Excel Templates, VB Code, and VB Functions
Write me if you have any questions

 

Google
 
Web www.dbelectronic.com

 

Excel Templates, VB Code, and VB Functions
Write me if you have any questions

 

 

Excel Templates:



Invoice.xls: I did not make this, although I have modified the front end for different needs. Works great otherwise!

Budget.xls: No, this is not my budget. BUT, it is basic and tells you what you need to make to pay your bills.
Wire List.xls: A simple spreadsheet for keeping track of wires, wire colors, wired numbers, etc.
Parts and Spares List.xls: Nice prefab worksheet using MTTR (Mean Time To Replace) and MTBF (Meant Time Between Failures)
Sales Price Break Chart.xls: Basic prefab chart I used for viewing price breaks.
Speed Test Results.xls: Uses a lot of interesting conditional formatting. An engineering type of sheet I made for analyzing the results of my students mouse trap car project. No guarantees on the accuracy of everything.
Samples/Sales.xls: Basic worksheet for samples and sales of your product.

 

Excel VB Code:

Gets the file name from the path:

'Gets the file name from the path.
Function GetFilename(FullName As String) As String
'GetFileName returns the file name, such as Cash.xls from
'the end of a full path such as C:\Data\Project1\Cash.xls
'stFullName is returned if no path separator is found

Dim PathSep As String 'Path Separator Character
Dim FNLength As Integer 'Length of stFullName
Dim i As Integer

PathSep = Application.PathSeparator
FNLength = Len(FullName)

'Find last path separator character, if any
For i = FNLength To 1 Step -1
If Mid(FullName, i, 1) = PathSep Then Exit For
GetFilename = Right(FullName, FNLength - i + 1)
Next i

End Function

 

Gets specific files from a folder and loads them into an array:

' Global variables

Public Filelist As Variant
Public Currentproject As Workbook
Public z As Integer

******* The above is part of the module global declaration*******

' Gets the files from the path and does not let the main project
' file to be added to.

Sub GetFileList()
Dim fs As Object
Dim i As Integer
Dim Name As String

Set fs = Application.FileSearch 'Set object

With fs
.LookIn = ThisWorkbook.Path 'Looks in this directory
.FileName = "*.xls" ' Filter Excel files
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 1 Then 'main 2 files are already there.
' Sort the files.

i = 1 ' Initialize the for loop count
z = 0 ' Initialize the Found files count
z = .FoundFiles.Count 'Amount of files found.
ReDim Filelist(1 To z) 'Redimension the array.

For i = 1 To z '
If Not .FoundFiles(i) = ThisWorkbook.FullName Then 'Filters out name of this file.
Name = GetFilename(.FoundFiles(i)) 'Assign current file to Name.
Filelist(i) = Name 'Add name to the array.
End If
Next i

If Filelist(1) = 0 Then ' If not files found.
GoTo Noway
End If

Else
Noway:
MsgBox "There were no files found!", , "Confirm"
Application.Quit
DoEvents

End If
End With
End Sub

 

This refreshes a range query:

Private Sub Refresh_Data()

On Error GoTo Cancel 'If error ya know.

' Refresh data.
Range("A1").QueryTable.Refresh BackgroundQuery:=False

GoTo Happiness 'If no error move on!

Cancel:
MsgBox "Macro cancelled"
End

Happiness: 'Is getting around an error.

End Sub

 

This exports data to a CSV. You could set it to export to other formats also:

Private Sub Export_Data()

' Save in current state
ThisWorkbook.Save

' Warn user to not save once "saved-as."
MsgBox "Once the file is saved as a .csv, close the file without saving.", 48, "Warning!"

' Get file name and path to Save As. *********Change name of CSV file below.
Fname = Application.GetSaveAsFilename(InitialFileName:="Your CSV List.csv", FileFilter:="Comma Separated Values (*.csv),*.xls")

' Save the file.
On Error GoTo Cancel

ThisWorkbook.SaveAs Filename:=Fname, FileFormat:=xlCSV, CreateBackup:=False

GoTo Happiness 'Continue if no error.

Cancel:
MsgBox "Macro Cancelled"
End

Happiness: 'Finish if no error.

End Sub

 

 
 
 
 
 
 
 
 

 

Excel Custom Functions:

Extracts the first name from a string with the the first and last name separated by a blank space:

Function FirstName(First) As String

Dim FNLength As Integer 'Length of First
Dim i As Integer

FNLength = Len(First)

' Find blank space
For i = 1 To FNLength
If Mid(First, i, 1) = " " Then Exit For
FirstName = Left(First, i)
Next i

End Function

 

Extracts the last name from a string with the the first and last name separated by a blank space:

Function LastName(Last) As String

Dim FNLength As Integer 'Length of Last
Dim i As Integer

FNLength = Len(Last)

' Find blank space
For i = FNLength To 1 Step -1
If Mid(Last, i, 1) = " " Then Exit For
LastName = Right(Last, FNLength - i + 1)
Next i

End Function

 

 

Google
 
Web www.dbelectronic.com

PHP Data Recovery
Links


Contact | Copyright 2007 DBElectronics
All Rights Reserved
Some Images used by permission from NASA.