orsettgreenboy
New Member
- Joined
- Sep 20, 2011
- Messages
- 22
Hello, hope someone can help
I have an existing routine that does three things
a) Generates next consecutive number to be added into new file name
b) Saves the file to our nextwork with this new file name
c) Sends me a copy via email.
This works very well see code below:
However, I now also need to copy the new file name together with certain cells contents to a third sheet which will be a log. Therefore the data copying over will need to be added to the next clear row available.
So to be clear there will be 3 files altogether
1) The original file (like a template / form for the user to fill out)
2) The saved as file (with a new file name each time)
3) The third is a file (a kind of log) which will receive the data from 2)
The new (third file) will have headings in Row A.
So the file name (from the second file) will need to be copied to Cell A2 the first time (if row 2 is clear), and next time to Cell A3, and so on.
Also the contents of cells B5,B7,B9,B11,B13,B15,B17,B19,B21,B23,B25,B27,B29,B31 & B33 will also need to be copied into the same row as the filename, starting at column B for B5, and column C for B7 etc.
I do hope I've explained that with enough information without being too longwinded!
Thanks for any help
I have an existing routine that does three things
a) Generates next consecutive number to be added into new file name
b) Saves the file to our nextwork with this new file name
c) Sends me a copy via email.
This works very well see code below:
Code:
Sub SvMe() 'Generate next number to B5 and Save filename as value of G9 then save onto P drive and email copy to me
Sheet1.Unprotect Password:="Monkey"
Range("B5") = Range("B5") + 1
Sheet1.Protect Password:="Monkey"
ActiveWorkbook.Save
Dim newFile As String, fName As String
fName = Range("G9").Value
newFile = fName
ActiveWorkbook.SaveAs Filename:="P:\Quality\Non Conformances\" & newFile, FileFormat:=IIf(Application.Version >= "12", 56, -4143)
Dim wb As Workbook
Dim I As Long
Set wb = ActiveWorkbook
If Val(Application.Version) >= 12 Then
If wb.FileFormat = 51 And wb.HasVBProject = True Then
MsgBox "There is VBA code in this xlsx file, there will" & vbNewLine & _
"be no VBA code in the file you send. Save the" & vbNewLine & _
"file first as xlsm and then try the macro again.", vbInformation
Exit Sub
End If
End If
On Error Resume Next
For I = 1 To 3
wb.SendMail "[EMAIL="rg@xxx.co.uk"]rg@xxx.co.uk[/EMAIL]", _
"Non Conformance"
If Err.Number = 0 Then Exit For
Next I
On Error GoTo 0
End Sub
However, I now also need to copy the new file name together with certain cells contents to a third sheet which will be a log. Therefore the data copying over will need to be added to the next clear row available.
So to be clear there will be 3 files altogether
1) The original file (like a template / form for the user to fill out)
2) The saved as file (with a new file name each time)
3) The third is a file (a kind of log) which will receive the data from 2)
The new (third file) will have headings in Row A.
So the file name (from the second file) will need to be copied to Cell A2 the first time (if row 2 is clear), and next time to Cell A3, and so on.
Also the contents of cells B5,B7,B9,B11,B13,B15,B17,B19,B21,B23,B25,B27,B29,B31 & B33 will also need to be copied into the same row as the filename, starting at column B for B5, and column C for B7 etc.
I do hope I've explained that with enough information without being too longwinded!
Thanks for any help