climivin
climivin

Reputation: 321

Where can I save the settings entered by the user?

VBA.

Step 1
The MS Project file is open;
The user starts the macro;
The form is opened;
The user enters the path;
The user clicks "Save";
The user closes the form;
The user closes the MS Project file.

Step 2
The user opens the MS Project file;
The user wins the macro;
The form is opened;
The form displays the path that the user has registered for "Stage 1";

enter image description here

Questions
How to make that when the user opens the form a second time (Step 2) in the form was displayed the path that was saved in (Step 1)?
In other words, after the form was closed (Step 1), the value of the textbox was retained?

Can this textbox value be saved in the MS Project file?
Or should I save it in a separate file?
How is this best done?

Upvotes: 2

Views: 333

Answers (3)

Malcolm Farrelle
Malcolm Farrelle

Reputation: 187

Further to Rachel's answer and in response to Jerred S.' comment, It is easy to overcome the 255 char limit of CustomDocumentProperties and to store War and Peace in there. Write a function such as function storeMyCDPstring(CDPNames as string, CDPVal as string). It will need to chop CDPVal into not-to-exceed 255 character packets and store these as indexed CustomDocumentProperties. Example, you want to store a 1000 char string in CustomDocumentProperty named "MyCDP". You adopt an arbitary naming convention - CDPs will be indexed by "#~#-n":

  • chars 1 to 255 will be stored as CustomDocumentProperty "myCDP#~#-1",
  • chars 256 to 510 will be stored as CustomDocumentProperty "myCDP#~#-2",
  • chars 511 to 765 will be stored as CustomDocumentProperty "myCDP#~#-3",
  • chars 766 to 1000 will be stored as CustomDocumentProperty "myCDP#~#-4"

You will need to write a function such as function getMyCDPstring(CDPNames as string) which must retrieve, concatenate and return all the substrings. You need also a managed delMyCDP function that will delete all the packets.

Upvotes: 0

Jerred S.
Jerred S.

Reputation: 376

A project's task 0 (the project summary task) is rarely used, so its notes field can be a good place to store long data. Unlike ActiveProject.CustomDocumentProperties, task 0's notes isn't constrained by a 255 character limit.

Accessing task 0's notes is a little tricky. On any other task, you'd use

ActiveProject.Tasks(someTaskID).Notes = "really long strings"
'where someTaskID is an integer variable

but task 0's notes are accessed by

ActiveProject.Comments = "really long strings"

Upvotes: 0

Rachel Hettinger
Rachel Hettinger

Reputation: 8442

Add a custom file property to store information in the MS Project file. For example:

Sub StorePath(newPath As String)
    Dim test As String
    test = GetPath()
    If Len(test) = 0 Then
        ActiveProject.CustomDocumentProperties.Add Name:="UserPath", LinkToContent:=False, Type:=msoPropertyTypeString, Value:=newPath
    Else
        ActiveProject.CustomDocumentProperties("UserPath") = newPath
    End If
End Sub

Function GetPath() As String
    On Error Resume Next
    GetPath = ActiveProject.CustomDocumentProperties("UserPath")
End Function

The information will be stored in the file itself, different files can have different paths stored, and if opened on another computer, the path is still available.

To save a single value on a user's computer, regardless of which file is opened, use SaveSetting and GetSetting, as mentioned by Sam in the comments above. These are not stored with the file and would not be visible on other computers.

Upvotes: 2

Related Questions