Open workbook debug

batuka

New Member
Joined
Jul 14, 2017
Messages
32
Code:
If month <= 9 Then

source_dizin = "G:\HOME\MALIKONT\_Hazine_Kontrol\TCU_" & year & "\Bilanço_Kontrolleri\Core_Pozisyon\(0" & month & ")_" & mmonth
source_file = source_dizin & "\CORE-MİZAN Pozisyon Kontrolü_" & year & "-0" & month & "-" & first_day & ".xlsx"
Else
source_dizin = "G:\HOME\MALIKONT\_Hazine_Kontrol\TCU_" & year & "\Bilanço_Kontrolleri\Core_Pozisyon\(" & month & ")_" & mmonth
source_file = source_dizin & "\CORE-MİZAN Pozisyon Kontrolü_" & year & "-" & month & "-" & first_day & ".xlsx"
End If




'pozisyon dosyası açma


[COLOR=#ff0000]Workbooks.Open (source_file), ReadOnly[/COLOR]
wb_core = ActiveWorkbook.Name

here is the part of my macro where it gives debug on Workbooks.Open (source_file), ReadOnly i couldn't figured out whats the problem please help
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
What is the error message? I suspect your value for source_file is incorrect and the code cannot open the file...
 
Upvote 0
I guess you get a Syntax error when you try executing the macro, as the correct syntax should be
Code:
Workbooks.Open (source_file), ReadOnly:=True
If this is not your case, then answer Jack's question: "What is the error message?"

Bye
 
Upvote 0
I agree with Jack. Just to add... Rid the parenthesis around source_file unless assigning (in this case, by Set). Also, your code as shown should fail due to the ReadOnly. Maybe something like:

Rich (BB code):
  If Len(Dir(source_file)) > 0 Then
    Workbooks.Open source_file, ReadOnly:=True
  Else
    MsgBox "Bad file name", vbInformation, vbNullString
    Exit Sub
  End If

Hope that helps,

Mark
 
Last edited:
Upvote 0
I agree with Jack. Just to add... Rid the parenthesis around source_file unless assigning (in this case, by Set). Also, your code as shown should fail due to the ReadOnly. Maybe something like:

Rich (BB code):
  If Len(Dir(source_file)) > 0 Then
    Workbooks.Open source_file, ReadOnly:=True
  Else
    MsgBox "Bad file name", vbInformation, vbNullString
    Exit Sub
  End If

Hope that helps,

Mark
I guess you get a Syntax error when you try executing the macro, as the correct syntax should be
Code:
Workbooks.Open (source_file), ReadOnly:=True

If this is not your case, then answer Jack's question: "What is the error message?"

Bye
What is the error message? I suspect your value for source_file is incorrect and the code cannot open the file...

thats the error
run time error 1004 Sorry we couldn't find is it possible it was moved renamed or deleted
 
Upvote 0
You need to make sure source_file has the correct string value, if it doesn't then you get the file not found error message.

See if this helps:
Code:
Dim strPath As String
Dim strFile As String

strPath = "G:\HOME\MALIKONT\_Hazine_Kontrol\TCU_@Year\Bilanço_Kontrolleri\Core_Pozisyon\(@Month)_@MMonth"
strFile = "@StrPath\CORE-MIZAN Pozisyon Kontrolü_@Year-@Month-@First_Day.xlsx"

strFile = Replace(strFile, "@StrPath", strPath)
strFile = Replace(strFile, "@Year", Year)
strFile = Replace(strFile, "@Month", Format(Month, "MM"))
strFile = Replace(strFile, "@MMonth", mmonth)
strFile = Replace(strFile, "@First_Day", first_day)

If MsgBox("Correct file? " & vbCrLf & vbCrLf & strFile, vbOKCancel, "Check File Name") = vbOK Then
    Workbooks.Open strFile, ReadOnly:=True
End If
I find evaluating strings difficult if there are too many concatenations and easier to debug string values, using Replace as suggested above.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top