Sub ブックの読み取り専用の切替2()
With ActiveWorkbook
If .ReadOnly Then
.ChangeFileAccess Mode:=xlReadWrite
Else
.ChangeFileAccess Mode:=xlReadOnly
End If
End With
End Sub
Dim wb As Workbook
Set wb = Workbooks.Open(fpath, , , , , , 1) '書き込みでブックを開く
Public Const NET As String = "\\個人フォルダ\13_金属相場\相場\"
Sub Ni書込()
Dim r As Range
Dim myFile As String
Dim Nendo As String
Dim シート名 As String
Dim 検索日 As String
Dim wb As Workbook
Nendo = Year(Date)
myFile = "Ni相場" & Nendo & ".xls"
シート名 = ThisWorkbook.Sheets("まとめ").Range("P21").Value
検索日 = ThisWorkbook.Sheets("まとめ").Range("Q21").Value
fpath = NET & "LME Ni相場\" & myFile
' Set wb = Workbooks.Open(fpath)
Set wb = Workbooks.Open(fpath, , , , , , 1) '書き込みでブックを開く
Dim myRange As Range
Dim myObj As Range
Dim keyWord As String
Set myRange = Range("A4:A26")
wb.Activate
Set myObj = myRange.Find(検索日, LookAt:=xlWhole)
If myObj Is Nothing Then
MsgBox "'" & myFile & 検索日 & "'はありませんでした"
Else
' MsgBox "'" & keyWord & "'は" & myObj.Row & "行目にあります"
' ActiveWorkbook.ChangeFileAccess Mode:=xlReadWrite '★書き込み切り替え
wb.Sheets(シート名).Range("B" & myObj.Row).Value = Workbooks("金属相場更新ファイルver2.xlsm").Worksheets("まとめ").Range("N21").Value
wb.Sheets(シート名).Range("D" & myObj.Row - 1).Value = Workbooks("金属相場更新ファイルver2.xlsm").Worksheets("まとめ").Range("N22").Value
wb.Save
wb.ChangeFileAccess Mode:=xlReadOnly '★読み込み切り替え
wb.Close
End If
Set myObj = Nothing
Set myRange = Nothing
End Sub