Send auto mail
Jeg har brug for hjælp til en af BAKs makroer, den kører perfekt når jeg i F1:M1 angiver at der skal søges i uge01-uge08, men når jeg angiver der skal søges i uge09-uge16 kommer der fejl.Makroen stopper ved: If GetValue(FilePath, v(UBound(v)), sheet, Cell2Get) > 0 Then
Hvorfor?
Dim FS As FileSearch
Dim FilePath As String, FilePathStart As String
Dim i As Integer, j As Integer
Dim v As Variant
Dim C As Range, rgFCell As Range
Dim Firmaer As Range
Dim Cell2Get
Const sheet As String = "Opgørelse"
With ThisWorkbook.Sheets(1)
Set Firmaer = .Range("A2:A" & .Range("A65536").End(xlUp).Row)
End With
FilePathStart = ThisWorkbook.path
Cell2Get = "B8"
Application.ScreenUpdating = False
Set FS = Application.FileSearch
For Each C In Range("F1:M1")
With FS
.NewSearch '**************Ny
.LookIn = FilePathStart & "\" & C & "\"
.FileType = msoFileTypeExcelWorkbooks '**************Ny / Ændret
.SearchSubFolders = False
.Execute
If .FoundFiles.Count = 0 Then GoTo Igen
For i = 1 To .FoundFiles.Count
v = Split(.FoundFiles(i), Application.PathSeparator)
FilePath = Left(.FoundFiles(i), InStrRev(.FoundFiles(i), Application.PathSeparator))
If GetValue(FilePath, v(UBound(v)), sheet, Cell2Get) > 0 Then
For Each rgFCell In Firmaer
If UCase(v(UBound(v))) Like "??" & UCase(rgFCell) & "*" Then '*****ændret
Cells(rgFCell.Row, C.Column) = .FoundFiles(i)
Exit For
End If
Next
End If
Next i
End With
Igen:
Next
End Sub
Private Function GetValue(path, file, sheet, range_ref)
Dim arg As String
arg = "'" & path & "[" & file & "]" & sheet & "'!" & Range(range_ref).Range("A1").Address(, , xlR1C1)
GetValue = ExecuteExcel4Macro(arg)
End Function
Sub Main()
Dim vfiler
Dim x As Boolean
Dim C As Range
BatchProcess
For Each C In Range("B2:B" & Range("B65536").End(xlUp).Row)
'********ÆNDRET RANGE ***************
vfiler = Range("F" & C.Row, "O" & C.Row)
'********EN NY PARAMETER SAT PÅ ***************
x = CreateMail(C.Value, C.Offset(0, 1), C.Offset(0, 2), C.Offset(0, 3), vfiler) 'ændret
'*************************************************
If x = False Then MsgBox C.Value & " ikke oprettet"
Next
End Sub
johnfm
