小编Nol*_*884的帖子

DLL函数无法在VBA环境中工作,但在Excel VBA中工作

我在Excel中编写的DLL(c ++)中包含以下函数,我在Excel中调试过,并且运行得很好:

float _stdcall ReturnT(LPCSTR FileName)
{

// Extracts the generic language string from the (importing BSTR  
// would import kanji or whatever) and converts it into a wstring
wstring str = CA2T(FileName);

// Sets the string to find as _t or _T followed by 2 or 3 digits and a subsequent _ or .
wregex ToFind(L"_[tT]\\d{2,3}(_|.)");
wsmatch TStr;

regex_search(str, TStr, ToFind);    // Now the wsmatch variable contains all the info about the matching
wstring T = TStr.str(0).erase(0, 2);    // …
Run Code Online (Sandbox Code Playgroud)

c++ string excel vba

9
推荐指数
1
解决办法
487
查看次数

在Excel.Chart中导出VB.NET Charting.Chart

假设我有一个Charting.Chart:

带有一些属性的图表

我想导出到一个Excel.Workbook.Worksheet以便以后可以"播放"数据(例如在Excel图表上拖放更多数据等):

不要介意曲线的差异

请不要介意第二张图表中的差异,尽可能接近第一张图表是最佳解决方案

是否有任何简单的方法可以导出保留其所有属性的第一个图表,或者至少是Excel接受的图表,或者我是否必须浏览每个属性?例如:

myCht.Title = myUserFormChart.Titles(0).Text
mySeries = myCht.Chart.SeriesCollection.NewSeries()
mySeries.Name = myUserFormChart.Series(0).Name
[...]
Run Code Online (Sandbox Code Playgroud)

vb.net charts interop export-to-excel

9
推荐指数
1
解决办法
661
查看次数

等待多个BackgroundWorkers完成

我必须使用多个大的二维数组(例如1024 x 128),在我的代码的一部分中,我需要转置一些(最多12个).该过程需要相当长的时间,我试图尽可能加快速度.知道VB.NET支持多线程我在这里和那里读了不同的源,并且可以在主子例程中提出以下代码:

RunXTransposingThreads(Arr1, Arr2, Arr3, ...)
Run Code Online (Sandbox Code Playgroud)

使用BackgroundWorkers作为我的解决方案的一部分:

Private Sub RunXTransposingThreads(ParamArray ArraysToTranspose() As Array)
    Dim x = CInt(ArraysToTranspose.GetLength(0)) - 1
    Dim i As Integer
    For i = 0 To x
        Dim worker As New System.ComponentModel.BackgroundWorker
        AddHandler worker.DoWork, AddressOf RunOneThread
        AddHandler worker.RunWorkerCompleted, AddressOf HandleThreadCompletion
        worker.RunWorkerAsync(ArraysToTranspose(i))
    Next
End Sub

Private Sub RunOneThread(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
    Dim Transposed(,) As Single = Array.CreateInstance(GetType(Single), 0, 0) ' I need this to be like that in order to use other …
Run Code Online (Sandbox Code Playgroud)

vb.net multithreading backgroundworker multidimensional-array

6
推荐指数
1
解决办法
390
查看次数

填写Internet Explorer输入框

我读了很多关于我的问题的答案,但不知怎的,如果我试图"模仿"我看到的东西,我仍然无法做我需要的东西.

问题非常简单:在打开的IE页面上填写输入框.

结果:代码卡在行上并getelementbyid显示运行时错误424(需要对象).

Private Sub AddInfoFromIntranet()

Dim ie As Object

Set ie = CreateObject("internetexplorer.application")
Application.SendKeys "{ESC}" ' I need this to ignore a prompt

With ie
    .Visible = True
    .navigate "{here goes the address of my website}"
    Do Until Not .Busy And .readyState = 4
        DoEvents
    Loop
    .document.getelementbyid("Nachnamevalue").Value = "{here goes whar I want to insert}"
End With

Set ie = Nothing

End Sub
Run Code Online (Sandbox Code Playgroud)

Internet Explorer库是自然导入的(否则"internetexplorer.application"将不起作用.

我很肯定我想要填写的字段被称为"Nachnamevalue",就像我今天早上在互联网上看到的那样.

我的网页的html代码(只有有趣的部分)看起来像这样:

<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
    '{here there are info …
Run Code Online (Sandbox Code Playgroud)

excel internet-explorer vba excel-vba inputbox

5
推荐指数
1
解决办法
2万
查看次数

Excel VBA - 是否可以通过使用矩阵为某个范围的每个单元格设置属性?

我最近发现可以使用单个命令在一个范围的每个单元格内设置值,如:

Worksheet.Range(Worksheet.Cells(Row1, Column1), Worksheet.Cells(Row2, Column2)) = MyMatrix
Run Code Online (Sandbox Code Playgroud)

MyMatrix2D矩阵在哪里,尺寸为:Row2-Row1和Column2-Column1.

显然,如果我将相同的属性应用于每个单元格(让我们说.Font.Bold- 何时MyMatrix是布尔矩阵),它不起作用:

Worksheet.Range(Worksheet.Cells(Row1, Column1), Worksheet.Cells(Row2, Column2)).Font.Bold = MyMatrix
Run Code Online (Sandbox Code Playgroud)

上面的命令使整个范围"粗体闪烁"几分之一秒,然后没有任何反应.怎么会?

我肯定想避免For循环,因为在我的代码中它需要太长时间.

更新:如果我填的是同一个甚至不工作MyMatrix与串"normal""bold",然后写:

Worksheet.Range(Worksheet.Cells(Row1, Column1), Worksheet.Cells(Row2, Column2)).Font.FontStyle = MyMatrix
Run Code Online (Sandbox Code Playgroud)

我也试过(它不起作用):

Worksheet.Range(Worksheet.Cells(Row1, Column1), Worksheet.Cells(Row2, Column2)).Cells.Font.FontStyle = MyMatrix
Run Code Online (Sandbox Code Playgroud)

excel vba matrix excel-vba cells

5
推荐指数
1
解决办法
2154
查看次数