Wrong code ?

Bomba
3StarLounger
Posts: 281
Joined: 20 Jan 2019, 19:43

Wrong code ?

Post by Bomba »

Hi,
In this code workbook ("1.xlsm") is in folder named "3. March 2019" and workbook [29.xlsm] is in folder named "2. February 2019". I have a command button to run this code. The problem is that when I click it workbook ("1.xlsm") is not updating from workbook ("29.xlsm") but it is opening workbook ("2.xlsm") of folder "3. March 2019". I tried to find if there is something wrong in the code but I can't manage.

Code: Select all

Sub SO()
Dim strPath As String
    strPath = CreateObject("WScript.Shell").SpecialFolders("MyDocuments")

dateStamp = Date

If Not Range("Q1").Value = dateStamp Then
    Range("Q1").Value = dateStamp
'// replace with your code below-------------
Workbooks("1.xlsm").Sheets("Chit1&2").Range("E20:H21").Value = "=" & "'" & strPath & "\My System\2. February 2019\[29.xlsm]Chit1&2'!E20:H21"
Workbooks("1.xlsm").Sheets("Chit3&4").Range("E20:H21").Value = "=" & "'" & strPath & "\My System\2. February 2019\[29.xlsm]Chit3&4'!E20:H21"
Workbooks("1.xlsm").Sheets("Chit5&6").Range("E20:H21").Value = "=" & "'" & strPath & "\My System\2. February 2019\[29.xlsm]Chit5&6'!E20:H21"
Workbooks("1.xlsm").Sheets("Chit1&2").Cells(8, "J").Value = "=" & "'" & strPath & "\My System\2. February 2019\[29.xlsm]Chit1&2'!J8"
Workbooks("1.xlsm").Sheets("Chit3&4").Cells(8, "J").Value = "=" & "'" & strPath & "\My System\2. February 2019\[29.xlsm]Chit3&4'!J8"
Workbooks("1.xlsm").Sheets("Chit5&6").Cells(8, "J").Value = "=" & "'" & strPath & "\My System\2. February 2019\[29.xlsm]Chit5&6'!J8"
    MsgBox "Code run for first time today!"
Else
    MsgBox "Code has already been run today!"
End If

End Sub


Thanks in advance.

Bomba
3StarLounger
Posts: 281
Joined: 20 Jan 2019, 19:43

Re: Wrong code ?

Post by Bomba »

Hi
I solved it. I had workbook [29.xlsm] named as [q9.xlsm].

Thanks

User avatar
HansV
Administrator
Posts: 78229
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Wrong code ?

Post by HansV »

:thumbup:
Best wishes,
Hans