1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'Begin Description
'This script changes the column width of the data editor to match the
'number of characters in each variables.  Overiding minimum and maximum
'values are defined immediately before the "Option Explicit" line
'The actual content of the variables are left unchanged
'Raynald Levesque 2002/05/23
'http://pages.infinit.net/rlevesqu/index.htm
'End Description

' Define min and max column width
Const IntMinLength As Integer = 7
Const IntMaxLength As Integer = 15

Option Explicit

Sub Main

	Dim objDocuments As ISpssDocuments
	Dim objDataDoc As ISpssDataDoc
	Dim objSpssInfo As ISpssInfo
	Dim varName As String
	Dim varList As String
	Dim intLength As Integer
	Dim i As Integer

	Set objDocuments = objSpssApp.Documents
	
	'Open data document if one is already open
	If objDocuments.DataDocCount <> 0 Then
		Set objDataDoc = objDocuments.GetDataDoc(0)
		objDataDoc.Visible=True
		Set objSpssInfo = objSpssApp.SpssInfo

		'Get the number of variables
		Dim varCount As Integer
		varCount = objSpssInfo.NumVariables
		If varCount = 0 Then
			End
		End If

		With objSpssInfo
		For i = 0 To varCount - 1
			varName = .VariableAt(i)
			'Uncomment next line if you only want to change column width of strings
			'If .VarType(i) = SpssDataString Then

			' Comment next line if you only want to change column width of strings
			If 1=1 Then
				'Make column width of length of this string variable
				'(subject to the min and max specified above)
				intLength = .VarLength(i)
				If IntMaxLength < .VarLength(i) Then intLength = IntMaxLength
				If IntMinLength > .VarLength(i) Then intLength = IntMinLength
				objSpssApp.ExecuteCommands ("VARIABLE WIDTH " & varName & " (" & intLength & ").",True)
			End If
		Next
		End With
	End If

	Set objDataDoc = Nothing
	Set objDocuments = Nothing
End Sub