tourless
Board Regular
- Joined
- Feb 8, 2007
- Messages
- 144
- Office Version
- 365
- Platform
- Windows
Hi Folks,
I've got this code...
The first thing you might notice is that ws is not actually declared. Curiously it runs on my machine. If I try to run it on another machine, it tells me it's not declared so I declare it as 'Dim ws as Worksheet'. No problem. Then I get a type mismatch on 'If ws.Name = weDate Then', which I understand.
My question is why would the code run successfully on one machine and not another?
I've got this code...
Code:
Option Explicit
Sub TransferToMain()
Dim sourceWB As Workbook, destWB As Workbook
Dim fName As String, strName As String
Dim weDate As Date
Dim iWeekDay As Integer
Dim LastRow As Long
'Set Source & Copy Sheet To Production File
Set sourceWB = ThisWorkbook
'Set date
weDate = Date
fName = "myfile"
Set destWB = Workbooks.Open("myotherfile")
'Call ReportOpen
'Copy the template
sourceWB.Sheets("Template").Copy After:=destWB.Sheets(destWB.Sheets.Count)
iWeekDay = Weekday(Now(), vbSunday)
weDate = Format(Now - (iWeekDay - 1), "mm-dd-yyyy")
For Each ws In Worksheets
If ws.Name = weDate Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
Else
End If
Next
ActiveSheet.Name = Format(weDate, "mm-dd-yyyy")
End Sub
My question is why would the code run successfully on one machine and not another?
Last edited by a moderator: