'Error: Can't move focus because it is invisible

I have the following code that works in all other circumstances except in a single where it returns the error "Can't move focus because it is invisible, not enable, or type that does not accept focus". The data in sheet consists only basic numbers and words. My objective is to select a range from one work book and paste it to another. It appear that excel does not recognise anything to be in the cells, although there in fact is. Does anyone know why this may be happening? Thanks in advance.

    Set Users = Application.Workbooks.Open(PathA)
        With Prices
        .Sheets("Sheet").Range("A:AJ").Select
        Selection.Copy
        End With
    'Set Risk = Application.Workbooks.Open(PathX)
        With Risk
        .Sheets("Sheet").Range("A1:AJ1048576").PasteSpecial Paste:=xlPasteAll
        .Save
       ' .Close
        End With
        Users.Close


Solution 1:[1]

it looks like someone else had the same issue and was able to resolve it on an MSDN forum

http://social.msdn.microsoft.com/Forums/office/en-US/3263b079-7e4f-452c-8dcc-92c682b8370b/excel-form-cant-move-focus-to-the-control-because-it-is-invisible-not-enabled-or-of-a-type-that?forum=exceldev

maybe this fix will apply to your situation too.

... OK so on that page, one guy has a kludge that seemed to work for him:

Error was:

Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus.

How to Fix

1. Select the object with the problem, e.g. the Form or Control.

2. In the properties windows, select the name of the object and rename adding an "x" to the end, e.g. Rename CPanel to CPanelx.

3. Save the Form.

4.Now rename the CPanelx back to CPanel.

5. Run your form.

6. Problem solved.

Something screwy with Excel VBA, not sure what !, but this will get you working again. Steve D.

and then someone else described the underlying problem, but his solution involved using design mode, which seems like it is maybe defeating the purpose of automating in vba, but the moderator seemed to like his answer better, so here that is as well

In normal use activeX controls are intended only to be activated, not selected, there's a difference. If you partifcularly want to Select the control (manually or with code), try putting Excel into Design mode first.

See also the topic "Why can't I select form and ActiveX controls?" in Excel's help (not VBA's help)

Peter Thornton

Solution 2:[2]

"Run-time error '-2147352565 (8002000b)': Can't move focus to the control because it is invisible, not enabled or of a type that does not accept the focus" Can be overcome but sequentially defining the area you wish to select. Obviously some may do this in any case, but it this specific instance it is needed to overcome the issue. This is an example for copying from one workbook to another and pasting where U is the sheet excel finds to be "invisible".

        Dim U As Workbook
        Dim Us As Worksheet
    Set U = Application.Workbooks.Open(Path)
    Set Us = U.Worksheets("sheet")
    With Us
        .Range("A:AJ").Select
        Selection.Copy
    End With
        U.Close SaveChanges = True
    With DestinationWorkbook
        .Sheets("sheet").Range("A:AJ").PasteSpecial Paste:=xlPasteAll
        .Save
    End With

Solution 3:[3]

Just to help in case you didn't find the answer till now : In my case this message came out when I redimensioned the application window while it was maximized :

e.g. Application.width = 100 (on Excel 2003 or 2007)

The solution in this case, is to first bring the application window to NORMAL.

e.g. ActiveWindow.WindowState = xlNormal

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 user2832896
Solution 3 4b0