現在、PowerPointで「OS」を作成しています。設定にグローバル変数を設定する方法を知る必要があります。
以下を含む「設定」というモジュールを作成しました。
Public Sub Settings()
Option Explicit
Public UserName, UserIcon, Background, BrowserHomePage As String
Public SetupComplete As Boolean
SetupComplete = False
UserName = "Administrator"
UserIcon = Nothing
Background = Nothing
BrowserHomePage = Nothing
'Set the variables
UserName.Text = UserName
End Sub
「ログイン」画面に、「UserName」という名前のテキストボックスが表示されます。次に、変数をテストするためだけにボタンを作成しました。ボタンはこれを行います:
Private Sub CommandButton1_Click()
UserName.Value = UserName
End Sub
ボタンをクリックしても、テキストボックスに値がありません。私はVBAを初めて使用するので、これを行う方法を知りたいです。また、PowerPointの起動時にコードを自動的に実行する方法を誰かが知っているなら、それは素晴らしいことです。
編集:設定のみを含むモジュールを作成しようとしています。スライドから値を変更する方法を誰かが指摘できますか?スライド1のボタンをクリックした場合と同様に、モジュール「設定」の「ユーザー名」の値を任意の値に変更します。
解決策:わかりました。1つの解決策を見つけました。設定をテキストファイルに書き込んで、読み取るために取得する必要があります。
私の設定モジュール:
Public UserName As String, Password As String, UserIcon As String, DesktopBackground As String, LogInBackground As String, BrowserHomePage As String
Public InitialSetupCompleted As Boolean
Public Sub ReadSettings()
'Delcaring variables
TempDir = Environ("Temp")
SettingsFileName = "\OpenOSSettings.txt"
SettingsFile = TempDir & SettingsFileName
ReadFile = FreeFile()
'Read all settings from file
Open SettingsFile For Input As #ReadFile
Do While Not EOF(ReadFile)
Line Input #ReadFile, Read
If Read Like "UserName = *" Then
UserName = Replace(Read, "UserName = ", "")
End If
If Read Like "Password = *" Then
Password = Replace(Read, "Password = ", "")
End If
If Read Like "UserIcon = *" Then
UserIcon = Replace(Read, "UserIcon = ", "")
End If
If Read Like "DesktopBackground = *" Then
DesktopBackground = Replace(Read, "DesktopBackground = ", "")
End If
If Read Like "LogInBackground = *" Then
LogInBackground = Replace(Read, "LogInBackground = ", "")
End If
If Read Like "BrowserHomePage = *" Then
BrowserHomePage = Replace(Read, "BrowserHomePage = ", "")
End If
If Read Like "InitialSetupCompleted = *" Then
InitialSetupCompleted = Replace(Read, "InitialSetupCompleted = ", "")
End If
Loop
Close #ReadFile
'Applying settings to all elements
Slide5.UserName.Caption = UserName
End Sub
Public Sub SaveSettings()
'Declaring variables
TempDir = Environ("Temp")
SettingsFileName = "\OpenOSSettings.txt"
SettingsFile = TempDir & SettingsFileName
WriteFile = FreeFile()
'Write all settings to file
Open SettingsFile For Output As #WriteFile
Print #WriteFile, "UserName = " & UserName
Print #WriteFile, "Password = " & Password
Print #WriteFile, "UserIcon = " & UserIcon
Print #WriteFile, "DesktopBackground = " & DesktopBackground
Print #WriteFile, "LogInBackground = " & LogInBackground
Print #WriteFile, "BrowserHomePage = " & BrowserHomePage
Print #WriteFile, "InitialSetupCompleted = " & InitialSetupCompleted
Close #WriteFile
End Sub
設定を保存するために、テキストボックスとボタンを使用します。TextBox1の値をファイルのUserNameに保存します。
Private Sub CommandButton1_Click()
UserName = TextBox1.Value
Settings.SaveSettings
End Sub
UserNameの値を読み取り、TextBox1に配置します。
Private Sub CommandButton2_Click()
Settings.ReadSettings
TextBox2.Value = UserName
End Sub
非常に長いコードですが、うまく機能します。みんな、ありがとう!