I'm trying to adapt some code that I found that allows me to access a website and update some base interest rate information into my workbook. It works, but has some issues. Can someone take a look at it and offer some suggestions?
I want the macro to run when I open the workbook and update the rates. It doesn't need to access the website after that. I just want to update it each time the workbook is opened. The data link works fine, but I'm having problems with importing the data to a sheet that is hidden (sheet is name "Magic" and most of the sheet is protected). I have unprotected the range where the data is imported, but I'm getting error messages when I open the workbook that says " The cell or chart that you are trying to change is protected and therefore read-only. To modify a protected cell or chart, firt remove protection using the Unprotect Sheet command (review tab, Changes,group). You may be prompted for a password."
I'd like to keep the sheet hidden and protected if possible. Is there a way to modify my code below to turn the protection off - allow the update- and then turn it back on?
My macro is below.
I want the macro to run when I open the workbook and update the rates. It doesn't need to access the website after that. I just want to update it each time the workbook is opened. The data link works fine, but I'm having problems with importing the data to a sheet that is hidden (sheet is name "Magic" and most of the sheet is protected). I have unprotected the range where the data is imported, but I'm getting error messages when I open the workbook that says " The cell or chart that you are trying to change is protected and therefore read-only. To modify a protected cell or chart, firt remove protection using the Unprotect Sheet command (review tab, Changes,group). You may be prompted for a password."
I'd like to keep the sheet hidden and protected if possible. Is there a way to modify my code below to turn the protection off - allow the update- and then turn it back on?
My macro is below.
Code:
Sub Import_H15_Rates()
'
' Import_H15 Macro
'
'
Application.ScreenUpdating = False
Sheets("Magic").Visible = True
Sheets("Magic").Select
ActiveSheet.Unprotect
Range("M100").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.federalreserve.gov/releases/h15/update/default.htm", _
Destination:=Range("$M$100"))
.Name = "default_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = True
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Range("M100").Select
ActiveSheet.Protect
Sheets("Magic").Visible = False
Sheets("Input").Select
Range("F12:K12").Select
End Sub
Last edited by a moderator: