diff --git a/dlls/mshtml/htmlstyle.c b/dlls/mshtml/htmlstyle.c
index f00619371a8..e21753bf59e 100644
--- a/dlls/mshtml/htmlstyle.c
+++ b/dlls/mshtml/htmlstyle.c
@@ -1491,22 +1491,7 @@ static HRESULT WINAPI HTMLStyle_put_marginRight(IHTMLStyle *iface, VARIANT v)
TRACE("(%p)->(v(%d))\n", This, V_VT(&v));
- switch(V_VT(&v)) {
- case VT_NULL:
- return set_style_attr(This, STYLEID_MARGIN_RIGHT, emptyW, 0);
- case VT_I4: {
- WCHAR buf[14];
-
- wsprintfW(buf, px_formatW, V_I4(&v));
- return set_style_attr(This, STYLEID_MARGIN_RIGHT, buf, 0);
- }
- case VT_BSTR:
- return set_style_attr(This, STYLEID_MARGIN_RIGHT, V_BSTR(&v), 0);
- default:
- FIXME("Unsupported vt=%d\n", V_VT(&v));
- }
-
- return E_NOTIMPL;
+ return set_nsstyle_attr_var(This->nsstyle, STYLEID_MARGIN_RIGHT, &v, ATTR_FIX_PX);
}
static HRESULT WINAPI HTMLStyle_get_marginRight(IHTMLStyle *iface, VARIANT *p)
diff --git a/dlls/mshtml/tests/style.c b/dlls/mshtml/tests/style.c
index bdb3dc2bf0b..4a0b9fb01db 100644
--- a/dlls/mshtml/tests/style.c
+++ b/dlls/mshtml/tests/style.c
@@ -370,6 +370,17 @@ static void test_body_style(IHTMLStyle *style)
ok(V_VT(&v) == VT_BSTR, "V_VT(marginRight) = %d\n", V_VT(&v));
ok(!V_BSTR(&v), "V_BSTR(marginRight) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
+ V_VT(&v) = VT_I4;
+ V_I4(&v) = 6;
+ hres = IHTMLStyle_put_marginRight(style, v);
+ ok(hres == S_OK, "put_marginRight failed: %08x\n", hres);
+
+ V_VT(&v) = VT_NULL;
+ hres = IHTMLStyle_get_marginRight(style, &v);
+ ok(hres == S_OK, "get_marginRight failed: %08x\n", hres);
+ ok(V_VT(&v) == VT_BSTR, "V_VT(marginRight) = %d\n", V_VT(&v));
+ ok(!strcmp_wa(V_BSTR(&v), "6px"), "V_BSTR(marginRight) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
+
V_VT(&v) = VT_NULL;
hres = IHTMLStyle_get_marginLeft(style, &v);
ok(hres == S_OK, "get_marginLeft failed: %08x\n", hres);