解除表单/工作簿Excel VBA

Sub VBA_Read_External_Workbook() ' Get customer workbook... Dim customerBook As Workbook Dim filter As String Dim caption As String Dim customerFilename As String Dim customerWorkbook As Workbook Dim targetWorkbook As Workbook Dim sheet As String ' make weak assumption that active workbook is the target Set targetWorkbook = Application.ActiveWorkbook ' get the customer workbook filter = "Text files (*.xlsb),*.xlsb" caption = "Please Select an input file " customerFilename = Application.GetOpenFilename(filter, , caption) Set customerWorkbook = Application.Workbooks.Open(customerFilename) sheet.Unprotect ("CADDRP") ' assume range is A1 - C10 in sheet1 ' copy data from customer to target workbook Dim targetSheet As Worksheet Set targetSheet = targetWorkbook.Worksheets(1) Dim sourceSheet As Worksheet Set sourceSheet = customerWorkbook.Worksheets(3) targetSheet.Range("A1", "C10").Value = sourceSheet.Range("D85", "D95").Value ' Close customer workbook customerWorkbook.Close 

结束小组

嗨,大家好,我已经设法得到这个工作,但我的一些客户端文件被保护。 所以search一下我设法挤压一行sheet.unprotect代码里面。 但它给了我一个错误,而不是“Object Required”运行时错误'424'。 我是一个擅长VBA的新手,如果能指出我正确的方向,我将不胜感激。 我猜我错过了过程中的一些variables声明?

假设您需要Unprotect 工作 ,而不是工作簿 。删除工作 。当前sheet.Unprotect工作 中的不Unprotect行,并设置SourceSheet 重新放回:

 Set sourceSheet = customerWorkbook.Worksheets(3) sourceSheet.Unprotect ("CADDRP")