An unexpected error ocurred with the method

P

Peter Rooney

Good afternoon, all.

Could anyone explain why the following code:

Sub Macro1()
SelectTaskColumn Column:="Text2"
ColumnDelete
End Sub

Results in the above message?

Thanks in advance

Pete
 
R

Rod Gill

Record a macro of you removing the column and you will find the TableEdit
method is recorded. It's a much more useful way of working with columns.
 
J

Jan De Messemaeker

Hi,

Because the text2 column wasn't visible in the active view.
It's the select that is impossible
HTH
 
P

Peter Rooney

Good morning, all,

Thanks for your help and suggestions - however, I'm still stumped.
Jan, the column is visible when I run the code to hide it, so i don't think
that that's the problem, although it IS the "SelecttaskColumn" line of code
that is highlighted when the error occurs, not the line that's actually
trying to do the hiding.

Rod, I DID record a macro of me hiding the column and the code I got is what
I pasted yesterday.

Jim, I tried your code and got exactly the same error message.

I can't delete the column, as I'm using it (in Task 1) to store a string
value containing a foldername that the user can alter, that I use in my save
macros, so I don't have to hard code the foldername in my VBA.

If anyone can suggest a better way of doing this, I'd be happy to listen.

P.S. The Text2 column is called "TopLevelFolder". Can I use either this or
"Text2" to refer to it . In any case, the "Hide" code still falls over.

P.P.S. Sorry if this seems an inane question - I've been living in Excel VBA
land for far too long! :)
 
P

Peter Rooney

All,
For additional information, Text1 (called "Comments") can be hidden using
the code
with no problems. I wonder what could be different about this column?

Pete
 
J

Jan De Messemaeker

Hi Peter,

I'm just as stumped because the code perfectly works for me.

Are you absolutely sure you don't run it twice (in which case the second
time would result in an error as the column has disappeared)

Is the right view/table activated?
How is the text column inserted?

Now about alternatives.

1. As for storing project-wide data, I do that either in a text field of the
project summary task (I deeply mistrust a user, he can delete tasks at will
and your information may disappear) or as a customdocumentproperty (lengthy
to write as you have to check whether the property exists, if necessary
create it...)

2. As for an altenative to enter it use inputbox, then store it wherever you
need;

3. I just tried it, you can use both names in the selectcolumn method

4. The tableedit method doesn't seem the best of iodeas: I do not know how
to delete a column using it.

Hope this helps,
 
P

Peter Rooney

Hold the front page (yeah, right)
I set up Text3, called "TLF" and this works fine, regardless of the name I
use to represent the column.
Can project documents become corrupted?. I can't work with text2 at all in
this way, yet Text3 is fine...

Also, can anyone advise as to how you can tell if a column is already
displayed, so the "unhide" code can be modified do that it isn't displayed
multiple times? Do columns have a visible property?

The Project MSDN board seems mighty quiet these days. Or is it me just
taking everybody's time up..? :)

Thankls in advance

Pete
 
P

Peter Rooney

Jan,
I recorded the following code to add the column (although there seems to be
an awful lot more than I think I need, I didn't delete anything, just in case)

Sub TopLevelFolderColumnUnhide() 'Control+L
SelectTaskColumn Column:="Work"
TableEdit Name:="&Entry", TaskTable:=True, _
NewName:="", FieldName:="", NewFieldName:="TLF", Title:="", _
Width:=30, Align:=2, ShowInMenu:=True, LockFirstColumn:=True,
DateFormat:=255, _
RowHeight:=1, ColumnPosition:=3, AlignTitle:=1
TableApply Name:="&Entry"
End Sub

By the way, did you see my other post in this thread about determining
whether a column is visible or not? Obviously, I don't want my show code to
display the column if it's already displayed! In response to your other
question, I created a new text field and it works perectly. I tried renaming
the "faulty" Text2 column, but nothing I do allows me to select it in order
to hide it. Corruption, maybe?

Once again, thanks for your interest and advice.

Pete
 
P

Peter Rooney

Jan,

Either you're serious, or you're just trying to convince me that I haven't
lost my marbles, but if there IS a bug, I'm quite happy just to use Text3, as
long as I know that i can't solve the problem! :)))
If you do happen to remember where you saw the article, can you point me in
its direction?
Also, any thoughts on a test for a column being visible (or not)?
Thanks very much
Regards

Pete
 
J

Jan De Messemaeker

Hi Peter,

Memory han't come back (yet) I'm fraid.
Which version are you using ? 02, 03? Std, Pro? Servcie pack 1, 2, none?

AFAIK table are write only so no way to verify the "visibility" of a field
:-(

Greetings,

Jan
 
P

Peter Rooney

Good afternoon, Jan.

I'm using 2003 Professional. 11.0.2003.0815.15

Just so you know, I'm trying to accomlish this in GANTT view - it's a pain,
as the user can display the column again and again - or conversely, hide it
then get an error message when they try to hide it again, when it's already
hidden! :-(

I'll keep trying!

Thanks again

Pete
 
J

Jan De Messemaeker

Hi Peter,

That is why I use Inputbox to ask for an input, then write it to wherever
without having to worry about activeview etc.
HTH
 
P

Peter Rooney

Jan,
I suppose you're right.
What I really need is a type of "Open" dialog box that will allow me to
navigate to a particular folder to select it, without seeing the files that
the folders contain, and using this folder name as a string within my Save
macro.

Regards & thanks again.

Pete
 
R

Roy G

Hi Peter,
I don't know if you are still interested in a solution or aleady found one
but you can use the following function to determine if a field is visible:

Function IsFieldVisible(ByVal field As String) As Boolean
Dim bVisible As Boolean
bVisible = False

SelectAll
For i = 1 To ActiveSelection.FieldNameList.Count
If field = ActiveSelection.FieldNameList.Item(i) Then
bVisible = True
Exit For
End If
Next
If bVisible = False Then
IsFieldVisible = False
Else
IsFieldVisible = True
End If

End Function

BTW, if you know of a better way please advise
Regards,
Roy Gilboa
 
P

Peter Rooney

Roy,

Thanks very much for this - it took me a while to remember what the question
was, but now I do..!

I'll give it a go.

regards

Pete
 
S

S Shipley

Roy,

I found this post of yours and your function helped solve my problem. Now
for some reason when I execute this code I get Run-time error 1101 Argument
is not valid. This only happens on text and flag fields I have added and when
I select them for deletion the who schedule gets highlighted but when I
select one of the named columns i.e. Unique ID the code works fine. Here is
a section of the code:

If CheckBox11 Then
IsFieldVisible ("Late?")
If bVisible Then
SelectTaskColumn Column:="Late?"
ColumnDelete
End If
CheckBox11.Value = False
End If

Late? is field Flag19. Any ideas of how to get around this or is this a
"feature" of MS Project?

Thanks,
Sam
 
S

S Shipley

I found a solution to my problem - when you pass the argument to
IsFieldVisible you have to use the title of the column not the defualt name
(this is true only for Text and Flag columns - at least that is what I have
found so far). To actually delete the column you have to use the default
name. I have updated the code as follows:
If CheckBox11 Then
IsFieldVisible ("Late?")
If bVisible Then
SelectTaskColumn Column:="Flag19"
ColumnDelete
End If
CheckBox11.Value = False
End If
 

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