Ik maak gebruik een script van ron de bruin om sheets te versturen naar verschillende mensen. Als er een emailadres in kolom O voorkomt, zal er een mail worden verstuurd naar dat emailadres. Echter ik krijg een foutmelding.
Het script:
Sub Mail_Every_Worksheet2()
Dim sh As Worksheet
Dim wb As Workbook
Dim strdate As String
Dim MyArrIndex As Long
Dim E_Mail_Count As Long
Dim cell As Range
Dim MyArr() As String
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
If sh.Range("a1").Value Like "*@*" Then
strdate = Format(Now, "dd-mm-yy h-mm-ss")
E_Mail_Count = sh.Columns("A").Cells.SpecialCells(xlCellTypeConstants).Count
ReDim MyArr(1 To E_Mail_Count)
MyArrIndex = 1
For Each cell In sh.Columns("A").Cells.SpecialCells(xlCellTypeConstants)
If cell Like "*@*" Then
MyArr(MyArrIndex) = cell.Value
MyArrIndex = MyArrIndex + 1
End If
Next
ReDim Preserve MyArr(1 To MyArrIndex)
sh.Copy
Set wb = ActiveWorkbook
With wb
.SaveAs "Sheet " & sh.Name & " of " _
& ThisWorkbook.Name & " " & strdate & ".xls"
.SendMail MyArr, _
"This is the Subject line"
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
End If
Next sh
Application.ScreenUpdating = True
End Sub
De foutmelding onstaat nadat de eerste sheet is verwerkt en is gemaild:
'Run time error 1004'
'Excel cannot access the file "C\program files\system\mapi\1033\nt
Several possible reasons:
* file name or path does not exist
* file you are trying to open is being used by another program. Close document in other program and try again.
*The name of the workbook you are trying to save is the same as the.......'
de laatste * wordt niet verder afgemaakt. De eerste 2 reasons zijn het naar mijn weten niet.
Iemand een idee hoe ik dit kan oplossen.
Deze 2 regels zou ik moeten debuggen volgens excel:
.SaveAs "Sheet " & sh.Name & " of " _
& ThisWorkbook.Name & " " & strdate & ".xls"
Het is een lang verhaal, maar kan iemand mij helpen?
Kan ik misschien zelf een map kiezen, waarin de files tijdelijk worden bewaard en waaruit ze ook weer worden verwijdert (als dit tenminste een oplossing zou zijn).
Alvast bedankt
Het script:
Sub Mail_Every_Worksheet2()
Dim sh As Worksheet
Dim wb As Workbook
Dim strdate As String
Dim MyArrIndex As Long
Dim E_Mail_Count As Long
Dim cell As Range
Dim MyArr() As String
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
If sh.Range("a1").Value Like "*@*" Then
strdate = Format(Now, "dd-mm-yy h-mm-ss")
E_Mail_Count = sh.Columns("A").Cells.SpecialCells(xlCellTypeConstants).Count
ReDim MyArr(1 To E_Mail_Count)
MyArrIndex = 1
For Each cell In sh.Columns("A").Cells.SpecialCells(xlCellTypeConstants)
If cell Like "*@*" Then
MyArr(MyArrIndex) = cell.Value
MyArrIndex = MyArrIndex + 1
End If
Next
ReDim Preserve MyArr(1 To MyArrIndex)
sh.Copy
Set wb = ActiveWorkbook
With wb
.SaveAs "Sheet " & sh.Name & " of " _
& ThisWorkbook.Name & " " & strdate & ".xls"
.SendMail MyArr, _
"This is the Subject line"
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
End If
Next sh
Application.ScreenUpdating = True
End Sub
De foutmelding onstaat nadat de eerste sheet is verwerkt en is gemaild:
'Run time error 1004'
'Excel cannot access the file "C\program files\system\mapi\1033\nt
Several possible reasons:
* file name or path does not exist
* file you are trying to open is being used by another program. Close document in other program and try again.
*The name of the workbook you are trying to save is the same as the.......'
de laatste * wordt niet verder afgemaakt. De eerste 2 reasons zijn het naar mijn weten niet.
Iemand een idee hoe ik dit kan oplossen.
Deze 2 regels zou ik moeten debuggen volgens excel:
.SaveAs "Sheet " & sh.Name & " of " _
& ThisWorkbook.Name & " " & strdate & ".xls"
Het is een lang verhaal, maar kan iemand mij helpen?
Kan ik misschien zelf een map kiezen, waarin de files tijdelijk worden bewaard en waaruit ze ook weer worden verwijdert (als dit tenminste een oplossing zou zijn).
Alvast bedankt