Unfortunately it still doesn't work properly. Same problem with the "Caption" line.
Thanks for the help anyway!
Unfortunately it still doesn't work properly. Same problem with the "Caption" line.
Thanks for the help anyway!
So i tried something here and it worked. So, what happens is that i have more checkboxes in this targets workbooks. I tried to remove all checkboxes from the workbooks before running the code, and without the other checkboxes, it works perfectly. But this doesn't really solves my problem, because i can't just remove all checkboxes from the workbooks.
I'm attaching 3 workbooks to see if it helps.
Still getting the same error. Posting the full code to see if there is something else wrong. If it helps, i can upload the set of workbooks i'm trying to run the code on.
Sub LoopThroughFiles()
folderName = "C:\Users\BSCAMPO1\Desktop\Orçamentos Geral"
If Right(folderName, 1) <> Application.PathSeparator Then folderName = folderName & Application.PathSeparator
Fname = Dir(folderName & "*.xlsx")
'loop through the files
Do While Len(Fname)
With Workbooks.Open(folderName & Fname)
With Sheets("Orçamento")
.CheckBoxes.Add(Left:=.Range("L12").Left, Top:=.Range("L12").Top, Width:=.Range("Y12").Width, Height:=.Range("L12").Height).Select
With Selection
.Caption = ""
.LinkedCell = "Parâmetros!A" & 27
End With
End With
End With
ActiveWorkbook.Close savechanges:=True
' go to the next file in the folder
Fname = Dir
Loop
End Sub
Display More
So the code consists in adding a checkbox with no label ("") on a specific cell on multiple workbooks. All workbooks have the same structure where the checkboxes are supposed to be added on the cell "L12" in a specific worksheet.
Because i have a considerable amount of workbooks, i tried to run a code that would open all workbooks in a folder, one by one, adding the checkbox, saving and then closing it. But when i run the code, it opens the first workbook in the folder, creates the checkbox (on the right place and with the right link) and when it goes to the second file in the folder, the checkbox created is added to a random place on the worksheet and the code stop running returning the error 438 and highlighting the lines ".Caption" and ".LinkedCell".
I hope i made it understandable. Sorry for any english mistakes.
Thanks for the instructions Roy!
Sorry for not reading the Forum Rules before posting my problem.
Hello! First time here.
I'm having some issues trying to add checkboxes in multiple workbooks. I created a loop to work throught all files in a specific folder, but it only works on the first file and when it goes to the next one, i get error 438, for the Caption and LinkedCell functions on my code. Hope someone can help!
Obs: The problem really is with the checkbox creation and definition of its parameters. I tried the code with different simple actions like defining cell values and it works perfectly.
Sub LoopThroughFiles()
folderName = "C:\******"
If Right(folderName, 1) <> Application.PathSeparator Then folderName = folderName & Application.PathSeparator
Fname = Dir(folderName & "*.xlsx")
'loop through the files
Do While Len(Fname)
With Workbooks.Open(folderName & Fname)
Sheets("Orçamento").CheckBoxes.Add(Left:=Range("L12").Left, Top:=Range("L12").Top, Width:=Range("Y12").Width, Height:=Range("L12").Height).Select
With Selection
.Caption = ""
.LinkedCell = "Parâmetros!A" & 27
End With
End With
ActiveWorkbook.Close savechanges:=True
' go to the next file in the folder
Fname = Dir
Loop
End Sub
Display More
Thanks for the attention!