셀에 입력한 msoShapeOval은 MsoShapeType으로 선언된 변수의 값이 될 수 없습니다. (msoShapeOval entered in cell not allowed to be value for variable declared as MsoShapeType)


문제 설명

셀에 입력한 msoShapeOval은 MsoShapeType으로 선언된 변수의 값이 될 수 없습니다. (msoShapeOval entered in cell not allowed to be value for variable declared as MsoShapeType)

첨부된 코드에서 shpOval3에 값을 할당하는 것을 제외하고 모든 것이 작동합니다.

셀에서 텍스트를 가져와 MsoShapeType으로 선언된 변수에 할당하려고 합니다.

1) 코드가 msoShapeOval의 셀 값을 shpOval3(MsoShapeType으로 선언됨)에 할당하려고 시도할 때 유형 불일치로 인해 오류가 발생합니다.

2) .Shapes에서 대신 strOval4(문자열)를 시도하면. AddShape(strOval4, Left, Top, Width, Height) 또한 잘못 실행되고 Type mismatch라고 표시됩니다.

셀 값이 로드될 때 셀에서 msoShapeType 상수로 변환하지 않으려고 합니다. 폼의 콤보 상자에 넣고 9의 값은 사용자에게 의미가 없습니다. 필요한 경우 변환할 수 있지만 변환하지 않고 솔루션을 찾고 있습니다.

Sub ShpType()

Dim shpOval1 As Long
Dim shpOval2 As MsoShapeType
Dim shpOval3 As MsoShapeType
Dim strOval4 As String

Sheets("Data").Range("Company1Shape") = "msoShapeOval"

shpOval1 = msoShapeOval
shpOval2 = msoShapeOval
shpOval3 = Sheets("Data").Range("Company1Shape")
strOval4 = Sheets("Data").Range("Company1Shape")

Debug.Print "shpOval1 = "; shpOval1
Debug.Print "shpOval2 = "; shpOval2
Debug.Print Sheets("Data").Range("Company1Shape")
Debug.Print "shpOval3 = "; shpOval3
Debug.Print "strOval4 = "; strOval4

End Sub
Debugger results with shpOval3 commented out
shpOval1 =  9 
shpOval2 =  9 
msoShapeOval
shpOval3 =  0 
strOval4 = msoShapeOval

참조 솔루션

방법 1:

You can use a Select Case statement to test your string and assign the appropriate constant to a variable declared as msoAutoShapeType...

Dim strShapeType As String
strShapeType = Sheets("Data").Range("Company1Shape")

Dim shapeType As MsoAutoShapeType
Select Case strShapeType
    Case "msoShapeOval"
        shapeType = msoShapeOval
    Case "msoShapeRectangle"
        shapeType = msoShapeRectangle
    'etc
    '
    '
    '
End Select

Hope this helps!

(by nonAPIDomenic)

참조 문서

  1. msoShapeOval entered in cell not allowed to be value for variable declared as MsoShapeType (CC BY‑SA 2.5/3.0/4.0)

#vba #excel






관련 질문

열에 문자열이 포함된 경우 열 번호 나열 (List column numbers if columns contain string)

SpinButton SpinUp 또는 SpinDown 새로 고침 (Refreshing SpinButton SpinUp or SpinDown)

변수를 사용하여 Excel VBA에서 3차원 배열 요소에 액세스 (Use variables to access 3 dimensional array elements in Excel VBA)

TODAY() 함수와 월 1일을 기준으로 범위 이동 (Moving a range based on TODAY() function and first of the month)

ALV 레이아웃의 표시된 모든 열을 제거하는 방법 (How to remove all displayed columns of ALV layout)

셀에 입력한 msoShapeOval은 MsoShapeType으로 선언된 변수의 값이 될 수 없습니다. (msoShapeOval entered in cell not allowed to be value for variable declared as MsoShapeType)

Excel VBA의 세로 열에 여러 json을 생성하는 방법은 무엇입니까? (How to generate multiple json in vertical column in Excel VBA?)

공개 함수의 VBA 런타임 오류 -2147319767(80028029) (VBA Run-time error -2147319767 (80028029) in Public Function)

알 수 없는 수의 문자를 패턴 일치시키는 방법 (How to Pattern Match an Unknown Number of Characters)

Excel VBA 파일이 열려 있는지 확인 기능 (Excel VBA Check if File is open function)

ActiveCell..Offset(-1,0)=을 사용하는 If/And/Then/Else 문의 VBA 문제= (VBA Issue with If/And/Then/Else statement using ActiveCell..Offset(-1,0)=)

VBA 런타임 오류 '1004': 응용 프로그램 정의 또는 개체 정의 오류" 설정 셀 내용 (VBA Runtime Error '1004': Application-defined or Object-defined error" setting cell contents)







코멘트