Greetings,
I am working on a basic job record that can go from quote to finished job and have created a string to store all the relevant reporting data on its own sheet within the file.
My thought is that various people will be able to create or update the job file and save it, while one expert would go into any files changed during the day and save those changes to a database.
This is trying to use Excel instead of a integrated relational database package that would probably do a better job than my hack - this is more fun!
So the first part is just to save the file and this seems to be working OK (but maybe you could point out redundant code in this) (The job number resides at B7)
Sub SaveJob()
'
' SaveJob Macro
' First part of File Saving
'
'
Sheets("Mock Quote Master").Select
ChDir "C:\Users\Albert15\Documents\LTP files\DevWork\Quotes"
Range("B7").Select
Selection.Copy
Application.CutCopyMode = False
Dim FName As String
Dim FPath As String
FPath = "C:\Users\Albert15\Documents\LTP files\DevWork\Quotes"
FName = Sheets("Mock Quote Master").Range("b7").Text
ThisWorkbook.SaveAs Filename:=FPath & "\" & FName & ".xlsm"
FileFormat = xlOpenXMLWorkbookMacroEnabled
End Sub
For writing to the database there are 2 scenarios - (A) It's an existing job that has been updated, it will already have an entry in the database (the job ref will be found in the column) and therefore the database will get more information at an existing line.
or (B) it's a new entry and I would like to write the data the the blank line below the last database entry. (I have called both PastePoint in the code below) The key and first cell of the database line is the same job reference as the saved job file.
Here I have tried to mimic some of the similar things I've read here but it's failing badly with my lack of VBA coding knowledge.. This is my attempt...
Sub SaveString()
'
' SaveString Macro
' First tests - Reporting Database must be open in background
'
'
Sheets("Mock Quote Master").Select
Range("B7").Select
Selection.CopyApplication.CutCopyMode = False
Dim FName As String
Dim FPath As String
Dim QRef As String
FPath = "C:\Users\Albert15\Documents\LTP files\DevWork\Quotes"
FName = Sheets("Mock Quote Master").Range("b7").Text
QRef = Sheets("Mock Quote Master").Range("b7").Text
Windows("Job Reporting Database.xlsx").Activate
Sheets("Database").Select
Columns("A:A").Select
Set PastePoint = Cells.Find(What = "Qref")
If Find Is Nothing Then
Range("A4").Select
Set PastePoint = Range(Selection, Selection.End(xlDown).Offset(1, 0)).Select
Windows(FPath & "\" & FName & ".xlsm").Activate
Application.WindowState = xlNormal
Sheets("Data String").Select
Range("A7:AI7").Select
Selection.Copy
Range("A8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A8:A18").Select
Application.CutCopyMode = False
Selection.Copy
Windows("Job Reporting Database.xlsx").Activate
GoTo PastePoint
Selection.Paste
ActiveWorkbook.Save
ActiveWindow.Close
End Sub
Thank you
Bookmarks