@@ -114,7 +114,8 @@ private void ExportUserFormModule(string path)
114
114
115
115
var tempFile = ExportToTempFile ( ) ;
116
116
var tempFilePath = Directory . GetParent ( tempFile ) . FullName ;
117
- var contents = File . ReadAllLines ( tempFile , System . Text . Encoding . UTF7 ) ;
117
+ var fileEncoding = System . Text . Encoding . Default ; //We use the current ANSI codepage because that is what the VBE does.
118
+ var contents = File . ReadAllLines ( tempFile , fileEncoding ) ;
118
119
var nonAttributeLines = contents . TakeWhile ( line => ! line . StartsWith ( "Attribute" ) ) . Count ( ) ;
119
120
var attributeLines = contents . Skip ( nonAttributeLines ) . TakeWhile ( line => line . StartsWith ( "Attribute" ) ) . Count ( ) ;
120
121
var declarationsStartLine = nonAttributeLines + attributeLines + 1 ;
@@ -130,7 +131,7 @@ private void ExportUserFormModule(string path)
130
131
contents . Skip ( declarationsStartLine + emptyLineCount - legitEmptyLineCount ) )
131
132
. ToArray ( ) ;
132
133
}
133
- File . WriteAllLines ( path , code ) ;
134
+ File . WriteAllLines ( path , code , fileEncoding ) ;
134
135
135
136
// LINQ hates this search, therefore, iterate the long way
136
137
foreach ( string line in contents )
@@ -165,8 +166,10 @@ private void ExportDocumentModule(string path)
165
166
var lineCount = CodeModule . CountOfLines ;
166
167
if ( lineCount > 0 )
167
168
{
169
+ //One cannot reimport document modules as such in the VBE; so we simply export and import the contents of the code pane.
170
+ //Because of this, it is OK, and actually preferable, to use the standard UTF8 encoding.
168
171
var text = CodeModule . GetLines ( 1 , lineCount ) ;
169
- File . WriteAllText ( path , text ) ;
172
+ File . WriteAllText ( path , text ) ;
170
173
}
171
174
}
172
175
0 commit comments