How can I access the "style" definitions in my Add-in?

D

Dreiding

I've created an Add-in to add a worksheet based on user inputs from a form.
I use custom style definitions (i.e. Range("A4").Style="myStyle") in my
Add-in.
Unfortunately Excel errors when trying to execute the code.

Is there a way to access the styles defined in the Add-in?

Thanks,
- Pat
 
M

michdenis

Hi,

Have you tried this :

Range("A4").Style="Workbooks("FileName.xla").Style("myStyle")



"Dreiding" <[email protected]> a écrit dans le message de groupe de
discussion : (e-mail address removed)...
I've created an Add-in to add a worksheet based on user inputs from a form.
I use custom style definitions (i.e. Range("A4").Style="myStyle") in my
Add-in.
Unfortunately Excel errors when trying to execute the code.

Is there a way to access the styles defined in the Add-in?

Thanks,
- Pat
 
D

Dave Peterson

Styles live in workbooks, so you'll have to merge your styles from the addin
into the other workbook.

Then you can apply that style to any range in the other workbook.

I created a style in my "sending" workbook/addin named Test1. Then I could use
this code.

Option Explicit
Sub testme01()
Dim FromWkbk As Workbook
Dim ToWkbk As Workbook

Set FromWkbk = Workbooks("myAddin.xla")
Set ToWkbk = Workbooks("book1.xls")

ToWkbk.Styles.Merge Workbook:=FromWkbk

ToWkbk.Worksheets(1).Range("c3").Style = "test1"

End Sub
 
D

Dave Peterson

And watch your double quotes, too.

But even with those corrections, this didn't work for me.
 
M

michdenis

I did not test. Effectively, it does not work. So, your response is appreciated.

Thanks.


"Dave Peterson" <[email protected]> a écrit dans le message de groupe de
discussion : (e-mail address removed)...
And watch your double quotes, too.

But even with those corrections, this didn't work for me.
 
D

Dreiding

Thanks for this solution. Here's the code I'll be using - maybe.

Sub testme02()
ActiveWorkbook.Styles.Merge ThisWorkbook
End Sub

I will have to call this macro before the styles are used.
Which is more efficient - Put an if statement checking if the styles are
already merged, or keep executiing testme02?

Sub testme03()
dim sStyle as string

on error resume next
sStyle = ActiveWorkbook.Styles("myStyle").Value
if sStyle="" then
ActiveWorkbook.Styles.Merge ThisWorkbook
end if
on error goto 0
end sub

- Pat
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top